Virtu/Virtu/Xna/MainGame.cs
Sean Fausett 2ba3146299 Replaced event handlers with direct delegates where appropriate.
Cosmetic changes including using C# 4 named and optional parameters.

--HG--
extra : convert_revision : svn%3Affd33b8c-2492-42e0-bdc5-587b920b7d6d/trunk%4046806
2010-05-28 10:48:08 +00:00

92 lines
2.9 KiB
C#

using Jellyfish.Library;
using Jellyfish.Virtu.Services;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
namespace Jellyfish.Virtu
{
public sealed class MainGame : GameBase
{
public MainGame() :
base("Virtu")
{
#if WINDOWS_PHONE
GraphicsDeviceManager.IsFullScreen = true;
GraphicsDeviceManager.PreferredBackBufferWidth = 480; // TODO remove; works around known ctp issue
GraphicsDeviceManager.PreferredBackBufferHeight = 800;
#endif
IsMouseVisible = true;
var frameRateCounter = new FrameRateCounter(this); // no initializers; avoids CA2000
Components.Add(frameRateCounter);
frameRateCounter.DrawOrder = 1;
frameRateCounter.FontName = "Consolas";
#if WINDOWS_PHONE
_storageService = new IsolatedStorageService(_machine);
#else
_storageService = new XnaStorageService(_machine, this);
#endif
_keyboardService = new XnaKeyboardService(_machine);
_gamePortService = new XnaGamePortService(_machine);
_audioService = new XnaAudioService(_machine, this);
_videoService = new XnaVideoService(_machine, this);
_machine.Services.AddService(typeof(StorageService), _storageService);
_machine.Services.AddService(typeof(KeyboardService), _keyboardService);
_machine.Services.AddService(typeof(GamePortService), _gamePortService);
_machine.Services.AddService(typeof(AudioService), _audioService);
_machine.Services.AddService(typeof(VideoService), _videoService);
}
protected override void Dispose(bool disposing)
{
if (disposing)
{
_machine.Dispose();
_storageService.Dispose();
_keyboardService.Dispose();
_gamePortService.Dispose();
_audioService.Dispose();
_videoService.Dispose();
}
base.Dispose(disposing);
}
protected override void BeginRun()
{
_machine.Start();
}
protected override void Update(GameTime gameTime)
{
_keyboardService.Update();
_gamePortService.Update();
base.Update(gameTime);
}
protected override void Draw(GameTime gameTime)
{
GraphicsDevice.Clear(Color.Black);
_videoService.Update();
base.Draw(gameTime);
}
protected override void EndRun()
{
_machine.Stop();
}
private Machine _machine = new Machine();
private StorageService _storageService;
private KeyboardService _keyboardService;
private GamePortService _gamePortService;
private AudioService _audioService;
private VideoService _videoService;
}
}