Modified video services to preserve aspect ratio on XNA+Xbox360.

--HG--
extra : convert_revision : svn%3Affd33b8c-2492-42e0-bdc5-587b920b7d6d/trunk%4044490
This commit is contained in:
Sean Fausett 2010-04-03 20:24:28 +00:00
parent 26bd5e3aa9
commit 21a9ba51dd
6 changed files with 36 additions and 33 deletions

View File

@ -14,7 +14,7 @@ public FrameRateCounter(GameBase game) :
FontName = "Default"; FontName = "Default";
//game.IsFixedTimeStep = true; // fixed (default) //game.IsFixedTimeStep = true; // fixed (default)
//game.TargetElapsedTime = TimeSpan.FromSeconds(1f / 60f); //game.TargetElapsedTime = TimeSpan.FromSeconds(1 / 60f);
//game.IsFixedTimeStep = false; // flatout //game.IsFixedTimeStep = false; // flatout
//game.GraphicsDeviceManager.SynchronizeWithVerticalRetrace = false; //game.GraphicsDeviceManager.SynchronizeWithVerticalRetrace = false;

View File

@ -69,6 +69,9 @@
<Reference Include="mscorlib"> <Reference Include="mscorlib">
<Private>False</Private> <Private>False</Private>
</Reference> </Reference>
<Reference Include="PresentationFramework">
<RequiredTargetFramework>3.0</RequiredTargetFramework>
</Reference>
<Reference Include="System"> <Reference Include="System">
<Private>False</Private> <Private>False</Private>
</Reference> </Reference>

View File

@ -11,13 +11,7 @@ public MainGame() :
base("Virtu") base("Virtu")
{ {
Components.Add(new FrameRateCounter(this) { DrawOrder = 1, FontName = "Consolas" }); Components.Add(new FrameRateCounter(this) { DrawOrder = 1, FontName = "Consolas" });
#if XBOX
GraphicsDeviceManager.PreferredBackBufferWidth = 640;
GraphicsDeviceManager.PreferredBackBufferHeight = 480;
#else
GraphicsDeviceManager.PreferredBackBufferWidth = 560;
GraphicsDeviceManager.PreferredBackBufferHeight = 384;
#endif
_storageService = new XnaStorageService(_machine, this); _storageService = new XnaStorageService(_machine, this);
_keyboardService = new XnaKeyboardService(_machine); _keyboardService = new XnaKeyboardService(_machine);
_gamePortService = new XnaGamePortService(_machine); _gamePortService = new XnaGamePortService(_machine);

View File

@ -21,10 +21,10 @@ public override void Update() // main thread
Vector2 right = _state.ThumbSticks.Right; Vector2 right = _state.ThumbSticks.Right;
GamePadDPad dpad = _state.DPad; GamePadDPad dpad = _state.DPad;
Paddle0 = (int)((1f + left.X) * PaddleScale); Paddle0 = (int)((1 + left.X) * PaddleScale);
Paddle1 = (int)((1f - left.Y) * PaddleScale); // invert y Paddle1 = (int)((1 - left.Y) * PaddleScale); // invert y
Paddle2 = (int)((1f + right.X) * PaddleScale); Paddle2 = (int)((1 + right.X) * PaddleScale);
Paddle3 = (int)((1f - right.Y) * PaddleScale); // invert y Paddle3 = (int)((1 - right.Y) * PaddleScale); // invert y
Joystick0 = GetJoystick(ref left, ref dpad); Joystick0 = GetJoystick(ref left, ref dpad);
Joystick1 = GetJoystick(ref right); Joystick1 = GetJoystick(ref right);
@ -55,7 +55,7 @@ private static Joystick GetJoystick(ref Vector2 thumbstick, ref GamePadDPad dpad
return new Joystick(isUp, isLeft, isRight, isDown); return new Joystick(isUp, isLeft, isRight, isDown);
} }
private const float PaddleScale = 128f; private const int PaddleScale = 128;
private const float JoystickDeadZone = 0.5f; private const float JoystickDeadZone = 0.5f;
private GamePadState _state; private GamePadState _state;

View File

@ -106,10 +106,12 @@ private void OnKeyUp(Keys key, bool gamePadControl)
{ {
Machine.Video.ToggleMonochrome(); Machine.Video.ToggleMonochrome();
} }
#if WINDOWS
else if ((control && (key == Keys.Subtract)) || (gamePadControl && (key == Keys.D0))) else if ((control && (key == Keys.Subtract)) || (gamePadControl && (key == Keys.D0)))
{ {
Machine.Video.ToggleFullScreen(); Machine.Video.ToggleFullScreen();
} }
#endif
} }
[SuppressMessage("Microsoft.Maintainability", "CA1502:AvoidExcessiveComplexity")] [SuppressMessage("Microsoft.Maintainability", "CA1502:AvoidExcessiveComplexity")]

View File

@ -1,5 +1,8 @@
using System; using System;
using System.Diagnostics.CodeAnalysis; using System.Diagnostics.CodeAnalysis;
#if WINDOWS
using System.Windows;
#endif
using Jellyfish.Library; using Jellyfish.Library;
using Microsoft.Xna.Framework; using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Graphics;
@ -32,21 +35,12 @@ public override void SetPixel(int x, int y, uint color)
public override void Update() // main thread public override void Update() // main thread
{ {
#if WINDOWS
if (_game.GraphicsDeviceManager.IsFullScreen != IsFullScreen) if (_game.GraphicsDeviceManager.IsFullScreen != IsFullScreen)
{ {
if (IsFullScreen)
{
_game.GraphicsDeviceManager.PreferredBackBufferWidth = _graphicsDevice.DisplayMode.Width; // avoids changing display mode
_game.GraphicsDeviceManager.PreferredBackBufferHeight = _graphicsDevice.DisplayMode.Height;
}
else
{
_game.GraphicsDeviceManager.PreferredBackBufferWidth = TextureWidth;
_game.GraphicsDeviceManager.PreferredBackBufferHeight = TextureHeight;
}
_game.GraphicsDeviceManager.ToggleFullScreen(); _game.GraphicsDeviceManager.ToggleFullScreen();
} }
#endif
if (_pixelsDirty) if (_pixelsDirty)
{ {
_pixelsDirty = false; _pixelsDirty = false;
@ -55,7 +49,7 @@ public override void Update() // main thread
_spriteBatch.Begin(SpriteBlendMode.None, SpriteSortMode.Immediate, SaveStateMode.None); _spriteBatch.Begin(SpriteBlendMode.None, SpriteSortMode.Immediate, SaveStateMode.None);
_graphicsDevice.SamplerStates[0].MagFilter = TextureFilter.Point; _graphicsDevice.SamplerStates[0].MagFilter = TextureFilter.Point;
_spriteBatch.Draw(_texture, _texturePosition, null, Color.White, 0f, Vector2.Zero, _textureScale, SpriteEffects.None, 0f); _spriteBatch.Draw(_texture, _texturePosition, null, Color.White, 0, Vector2.Zero, _textureScale, SpriteEffects.None, 0);
_spriteBatch.End(); _spriteBatch.End();
} }
@ -72,15 +66,25 @@ private void OnGraphicsDeviceManagerPreparingDeviceSettings(object sender, Prepa
{ {
DisplayMode displayMode = e.GraphicsDeviceInformation.Adapter.CurrentDisplayMode; DisplayMode displayMode = e.GraphicsDeviceInformation.Adapter.CurrentDisplayMode;
PresentationParameters presentationParameters = e.GraphicsDeviceInformation.PresentationParameters; PresentationParameters presentationParameters = e.GraphicsDeviceInformation.PresentationParameters;
_textureScale = Math.Min(presentationParameters.BackBufferWidth / TextureWidth, presentationParameters.BackBufferHeight / TextureHeight);
while ((presentationParameters.BackBufferWidth + TextureWidth <= displayMode.Width) && #if WINDOWS
(presentationParameters.BackBufferHeight + TextureHeight <= displayMode.Height)) if (presentationParameters.IsFullScreen)
{ {
presentationParameters.BackBufferWidth += TextureWidth; _textureScale = Math.Min((int)SystemParameters.PrimaryScreenWidth / TextureWidth, (int)SystemParameters.PrimaryScreenHeight / TextureHeight);
presentationParameters.BackBufferHeight += TextureHeight; presentationParameters.BackBufferWidth = displayMode.Width; // avoids changing display mode
_textureScale++; presentationParameters.BackBufferHeight = displayMode.Height;
} }
else
{
_textureScale = Math.Min((int)SystemParameters.FullPrimaryScreenWidth / TextureWidth, (int)SystemParameters.FullPrimaryScreenHeight / TextureHeight);
presentationParameters.BackBufferWidth = _textureScale * TextureWidth;
presentationParameters.BackBufferHeight = _textureScale * TextureHeight;
}
#else
_textureScale = Math.Min(displayMode.TitleSafeArea.Width / TextureWidth, displayMode.TitleSafeArea.Height / TextureHeight);
presentationParameters.BackBufferWidth = displayMode.Width; // always use display mode
presentationParameters.BackBufferHeight = displayMode.Height;
#endif
} }
private void OnGraphicsDeviceServiceDeviceCreated(object sender, EventArgs e) private void OnGraphicsDeviceServiceDeviceCreated(object sender, EventArgs e)
@ -94,8 +98,8 @@ private void OnGraphicsDeviceServiceDeviceCreated(object sender, EventArgs e)
private void SetTexturePosition() private void SetTexturePosition()
{ {
_texturePosition.X = (_graphicsDevice.PresentationParameters.BackBufferWidth - TextureWidth * _textureScale) / 2f; // centered _texturePosition.X = (_graphicsDevice.PresentationParameters.BackBufferWidth - TextureWidth * _textureScale) / 2; // centered
_texturePosition.Y = (_graphicsDevice.PresentationParameters.BackBufferHeight - TextureHeight * _textureScale) / 2f; _texturePosition.Y = (_graphicsDevice.PresentationParameters.BackBufferHeight - TextureHeight * _textureScale) / 2;
} }
private const int TextureWidth = 560; private const int TextureWidth = 560;