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 @@ namespace Jellyfish.Library
FontName = "Default";
//game.IsFixedTimeStep = true; // fixed (default)
//game.TargetElapsedTime = TimeSpan.FromSeconds(1f / 60f);
//game.TargetElapsedTime = TimeSpan.FromSeconds(1 / 60f);
//game.IsFixedTimeStep = false; // flatout
//game.GraphicsDeviceManager.SynchronizeWithVerticalRetrace = false;

View File

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

View File

@ -11,13 +11,7 @@ namespace Jellyfish.Virtu
base("Virtu")
{
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);
_keyboardService = new XnaKeyboardService(_machine);
_gamePortService = new XnaGamePortService(_machine);

View File

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

View File

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

View File

@ -1,5 +1,8 @@
using System;
using System.Diagnostics.CodeAnalysis;
#if WINDOWS
using System.Windows;
#endif
using Jellyfish.Library;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
@ -32,21 +35,12 @@ namespace Jellyfish.Virtu.Services
public override void Update() // main thread
{
#if WINDOWS
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();
}
#endif
if (_pixelsDirty)
{
_pixelsDirty = false;
@ -55,7 +49,7 @@ namespace Jellyfish.Virtu.Services
_spriteBatch.Begin(SpriteBlendMode.None, SpriteSortMode.Immediate, SaveStateMode.None);
_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();
}
@ -72,15 +66,25 @@ namespace Jellyfish.Virtu.Services
{
DisplayMode displayMode = e.GraphicsDeviceInformation.Adapter.CurrentDisplayMode;
PresentationParameters presentationParameters = e.GraphicsDeviceInformation.PresentationParameters;
_textureScale = Math.Min(presentationParameters.BackBufferWidth / TextureWidth, presentationParameters.BackBufferHeight / TextureHeight);
while ((presentationParameters.BackBufferWidth + TextureWidth <= displayMode.Width) &&
(presentationParameters.BackBufferHeight + TextureHeight <= displayMode.Height))
#if WINDOWS
if (presentationParameters.IsFullScreen)
{
presentationParameters.BackBufferWidth += TextureWidth;
presentationParameters.BackBufferHeight += TextureHeight;
_textureScale++;
_textureScale = Math.Min((int)SystemParameters.PrimaryScreenWidth / TextureWidth, (int)SystemParameters.PrimaryScreenHeight / TextureHeight);
presentationParameters.BackBufferWidth = displayMode.Width; // avoids changing display mode
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)
@ -94,8 +98,8 @@ namespace Jellyfish.Virtu.Services
private void SetTexturePosition()
{
_texturePosition.X = (_graphicsDevice.PresentationParameters.BackBufferWidth - TextureWidth * _textureScale) / 2f; // centered
_texturePosition.Y = (_graphicsDevice.PresentationParameters.BackBufferHeight - TextureHeight * _textureScale) / 2f;
_texturePosition.X = (_graphicsDevice.PresentationParameters.BackBufferWidth - TextureWidth * _textureScale) / 2; // centered
_texturePosition.Y = (_graphicsDevice.PresentationParameters.BackBufferHeight - TextureHeight * _textureScale) / 2;
}
private const int TextureWidth = 560;