Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Revert "Revert "Merge branch 'develop3d' of https://github.com/Sickhe…

…adGames/MonoGame into develop3d""

This reverts commit 075a3c9.
  • Loading branch information...
commit 7c2fa0f1eefd3b09a57e0c53aae8889dfc4ea212 1 parent 075a3c9
@tomspilman tomspilman authored
View
25 MonoGame.Framework.iOS.sln
@@ -58,5 +58,30 @@ Global
EndGlobalSection
GlobalSection(MonoDevelopProperties) = preSolution
StartupItem = MonoGame.Framework\MonoGame.Framework.iOS.csproj
+ Policies = $0
+ $0.TextStylePolicy = $1
+ $1.inheritsSet = null
+ $1.scope = text/x-csharp
+ $0.CSharpFormattingPolicy = $2
+ $2.NamespaceBraceStyle = EndOfLine
+ $2.ClassBraceStyle = EndOfLine
+ $2.InterfaceBraceStyle = EndOfLine
+ $2.StructBraceStyle = EndOfLine
+ $2.EnumBraceStyle = EndOfLine
+ $2.AfterDelegateDeclarationParameterComma = True
+ $2.BeforeSizeOfParentheses = True
+ $2.BeforeTypeOfParentheses = True
+ $2.SpacesAfterTypecast = True
+ $2.SpacesBeforeArrayDeclarationBrackets = True
+ $2.inheritsSet = Mono
+ $2.inheritsScope = text/x-csharp
+ $2.scope = text/x-csharp
+ $0.TextStylePolicy = $3
+ $3.FileWidth = 120
+ $3.RemoveTrailingWhitespace = True
+ $3.EolMarker = Unix
+ $3.inheritsSet = Mono
+ $3.inheritsScope = text/plain
+ $3.scope = text/plain
EndGlobalSection
EndGlobal
View
16 MonoGame.Framework/Android/XnaGameWindowImpl.cs
@@ -45,14 +45,6 @@ public override Rectangle ClientBounds
public override DisplayOrientation CurrentOrientation
{
get { return nativeWindow.CurrentOrientation; }
- internal set
- {
- if (nativeWindow.CurrentOrientation != value)
- {
- //nativeWindow.CurrentOrientation = value;
- OnOrientationChanged();
- }
- }
}
public override IntPtr Handle
@@ -69,5 +61,11 @@ protected override void SetTitle(string title)
{
nativeWindow.Title = title;
}
+
+ // FIXME: Implement SetSupportedOrientations
+ protected internal override void SetSupportedOrientations(DisplayOrientation orientations)
+ {
+ Console.WriteLine("Android needs to implement GameWindow.SetSupportedOrientations!");
+ }
}
-}
+}
View
26 MonoGame.Framework/Desktop/OpenTKGameWindow.cs
@@ -87,12 +87,6 @@ public class OpenTKGameWindow : GameWindow
public override Rectangle ClientBounds { get { return clientBounds; } }
- public override string Title
- {
- get { return window.Title; }
- set { SetTitle(value); }
- }
-
// TODO: this is buggy on linux - report to opentk team
public override bool AllowUserResizing
{
@@ -109,18 +103,12 @@ public override bool AllowUserResizing
public override DisplayOrientation CurrentOrientation
{
- get
- {
- return _currentOrientation;
- }
- internal set
- {
- if (value != _currentOrientation)
- {
- _currentOrientation = value;
- OnOrientationChanged();
- }
- }
+ get { return DisplayOrientation.LandscapeLeft; }
+ }
+
+ protected internal override void SetSupportedOrientations(DisplayOrientation orientations)
+ {
+ // Do nothing. Desktop platforms don't do orientation.
}
#endregion
@@ -314,8 +302,6 @@ public override void EndScreenDeviceChange(string screenDeviceName, int clientWi
}
- public override void EndScreenDeviceChange(string screenDeviceName) { }
-
#endregion
#region Events
View
13 MonoGame.Framework/Game.cs
@@ -128,7 +128,6 @@ public Game()
{
_instance = this;
LaunchParameters = new LaunchParameters();
- Exiting += OnExiting;
_services = new GameServiceContainer();
_components = new GameComponentCollection();
Content = new ContentManager(_services);
@@ -337,20 +336,13 @@ internal bool Initialized
public void Exit()
{
- Raise(Exiting, EventArgs.Empty);
_platform.Exit();
}
public void ResetElapsedTime()
{
- // FIXME: This method didn't actually do anything before. It
- // may need to call a new method in GamePlatform to allow
- // platforms to handle elapsed time in their own way.
- // Now that things are more unified, it may be possible to
- // consolidate this logic back into the Game class.
- // Regardless, an empty implementation is not correct.
_platform.ResetElapsedTime();
- _lastUpdate = DateTime.Now;
+ _lastUpdate = DateTime.Now;
}
public void Run()
@@ -377,6 +369,7 @@ public void Run(GameRunBehavior runBehavior)
case GameRunBehavior.Synchronous:
_platform.RunLoop();
EndRun();
+ OnExiting(this, EventArgs.Empty);
break;
default:
throw new NotImplementedException(string.Format(
@@ -512,6 +505,7 @@ protected virtual void Update(GameTime gameTime)
protected virtual void OnExiting(object sender, EventArgs args)
{
+ Raise(Exiting, EventArgs.Empty);
}
#endregion Protected Methods
@@ -540,6 +534,7 @@ private void Platform_AsyncRunLoopEnded(object sender, EventArgs e)
var platform = (GamePlatform)sender;
platform.AsyncRunLoopEnded -= Platform_AsyncRunLoopEnded;
EndRun();
+ OnExiting(this, EventArgs.Empty);
}
private void Platform_Activated(object sender, EventArgs e)
View
213 MonoGame.Framework/GameWindow.cs
@@ -1,59 +1,154 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using Microsoft.Xna.Framework;
-
-namespace Microsoft.Xna.Framework
-{
- public abstract class GameWindow
- {
- public event EventHandler<EventArgs> ClientSizeChanged;
- public event EventHandler<EventArgs> OrientationChanged;
- public event EventHandler<EventArgs> ScreenDeviceNameChanged;
-
- public abstract void BeginScreenDeviceChange(bool willBeFullScreen);
- public abstract void EndScreenDeviceChange(string screenDeviceName, int clientWidth, int clientHeight);
-
- public virtual void EndScreenDeviceChange(string screenDeviceName) { }
-
- protected void OnActivated(){}
-
- protected void OnClientSizeChanged()
- {
- if (ClientSizeChanged != null)
- {
- ClientSizeChanged(this, EventArgs.Empty);
- }
- }
-
- protected void OnDeactivated(){}
-
- protected void OnOrientationChanged()
- {
- if (OrientationChanged != null)
- {
- OrientationChanged(this, EventArgs.Empty);
- }
- }
-
- protected void OnPaint(){}
-
- protected void OnScreenDeviceNameChanged()
- {
- if (ScreenDeviceNameChanged != null)
- {
- ScreenDeviceNameChanged(this, EventArgs.Empty);
- }
- }
-
- public abstract bool AllowUserResizing { get; set; }
- public abstract Rectangle ClientBounds { get; }
- public abstract DisplayOrientation CurrentOrientation { get; internal set; }
- public abstract IntPtr Handle { get; }
- public abstract string ScreenDeviceName { get; }
-
- public virtual string Title { get; set; }
- protected abstract void SetTitle(string title);
- }
-}
+#region License
+/*
+Microsoft Public License (Ms-PL)
+MonoGame - Copyright © 2009-2012 The MonoGame Team
+
+All rights reserved.
+
+This license governs use of the accompanying software. If you use the software,
+you accept this license. If you do not accept the license, do not use the
+software.
+
+1. Definitions
+
+The terms "reproduce," "reproduction," "derivative works," and "distribution"
+have the same meaning here as under U.S. copyright law.
+
+A "contribution" is the original software, or any additions or changes to the
+software.
+
+A "contributor" is any person that distributes its contribution under this
+license.
+
+"Licensed patents" are a contributor's patent claims that read directly on its
+contribution.
+
+2. Grant of Rights
+
+(A) Copyright Grant- Subject to the terms of this license, including the
+license conditions and limitations in section 3, each contributor grants you a
+non-exclusive, worldwide, royalty-free copyright license to reproduce its
+contribution, prepare derivative works of its contribution, and distribute its
+contribution or any derivative works that you create.
+
+(B) Patent Grant- Subject to the terms of this license, including the license
+conditions and limitations in section 3, each contributor grants you a
+non-exclusive, worldwide, royalty-free license under its licensed patents to
+make, have made, use, sell, offer for sale, import, and/or otherwise dispose of
+its contribution in the software or derivative works of the contribution in the
+software.
+
+3. Conditions and Limitations
+
+(A) No Trademark License- This license does not grant you rights to use any
+contributors' name, logo, or trademarks.
+
+(B) If you bring a patent claim against any contributor over patents that you
+claim are infringed by the software, your patent license from such contributor
+to the software ends automatically.
+
+(C) If you distribute any portion of the software, you must retain all
+copyright, patent, trademark, and attribution notices that are present in the
+software.
+
+(D) If you distribute any portion of the software in source code form, you may
+do so only under this license by including a complete copy of this license with
+your distribution. If you distribute any portion of the software in compiled or
+object code form, you may only do so under a license that complies with this
+license.
+
+(E) The software is licensed "as-is." You bear the risk of using it. The
+contributors give no express warranties, guarantees or conditions. You may have
+additional consumer rights under your local laws which this license cannot
+change. To the extent permitted under your local laws, the contributors exclude
+the implied warranties of merchantability, fitness for a particular purpose and
+non-infringement.
+*/
+#endregion License
+
+using System;
+using System.ComponentModel;
+
+namespace Microsoft.Xna.Framework {
+ public abstract class GameWindow {
+ #region Properties
+
+ [DefaultValue(false)]
+ public abstract bool AllowUserResizing { get; set; }
+
+ public abstract Rectangle ClientBounds { get; }
+
+ public abstract DisplayOrientation CurrentOrientation { get; }
+
+ public abstract IntPtr Handle { get; }
+
+ public abstract string ScreenDeviceName { get; }
+
+ private string _title;
+ public string Title {
+ get { return _title; }
+ set {
+ if (_title != value) {
+ SetTitle(value);
+ _title = value;
+ }
+ }
+ }
+
+ #endregion Properties
+
+ #region Events
+
+ public event EventHandler<EventArgs> ClientSizeChanged;
+ public event EventHandler<EventArgs> OrientationChanged;
+ public event EventHandler<EventArgs> ScreenDeviceNameChanged;
+
+ #endregion Events
+
+ public abstract void BeginScreenDeviceChange (bool willBeFullScreen);
+
+ public abstract void EndScreenDeviceChange (
+ string screenDeviceName, int clientWidth, int clientHeight);
+
+ public void EndScreenDeviceChange (string screenDeviceName)
+ {
+ EndScreenDeviceChange(screenDeviceName, ClientBounds.Width, ClientBounds.Height);
+ }
+
+ protected void OnActivated ()
+ {
+ }
+
+ protected void OnClientSizeChanged ()
+ {
+ var handler = ClientSizeChanged;
+ if (handler != null)
+ handler (this, EventArgs.Empty);
+ }
+
+ protected void OnDeactivated ()
+ {
+ }
+
+ protected void OnOrientationChanged ()
+ {
+ var handler = OrientationChanged;
+ if (handler != null)
+ OrientationChanged (this, EventArgs.Empty);
+ }
+
+ protected void OnPaint ()
+ {
+ }
+
+ protected void OnScreenDeviceNameChanged ()
+ {
+ var handler = ScreenDeviceNameChanged;
+ if (handler != null)
+ handler (this, EventArgs.Empty);
+ }
+
+ protected internal abstract void SetSupportedOrientations (DisplayOrientation orientations);
+ protected abstract void SetTitle (string title);
+ }
+}
View
3  MonoGame.Framework/GamerServices/GamerServicesComponent.cs
@@ -39,7 +39,7 @@ 1. Definitions
#endregion License
#region Using Statements
-using System;
+using System;
using Microsoft.Xna.Framework.Net;
#endregion Statements
@@ -55,7 +55,6 @@ public class GamerServicesComponent : GameComponent
public GamerServicesComponent(Game game) : base(game)
{
lng = new LocalNetworkGamer();
- Guide.Window = game.Window;
Guide.Initialise(game);
}
View
8 MonoGame.Framework/GraphicsDeviceManager.cs
@@ -91,6 +91,7 @@ public void CreateDevice()
_graphicsDevice = new GraphicsDevice();
Initialize();
+ ApplyChanges();
OnDeviceCreated(EventArgs.Empty);
}
@@ -153,16 +154,15 @@ public void Dispose()
public void ApplyChanges()
{
+ _game.Window.SetSupportedOrientations(_supportedOrientations);
}
private void Initialize()
{
// Set "full screen" as default
_graphicsDevice.PresentationParameters.IsFullScreen = true;
-#if IPHONE
- _graphicsDevice.glFramebuffer = _game.Window.Framebuffer;
-#endif
- if (_preferMultiSampling)
+
+ if (_preferMultiSampling)
{
_graphicsDevice.PreferedFilter = All.Linear;
}
View
87 MonoGame.Framework/Input/Touch/TouchCollection.cs
@@ -53,9 +53,6 @@ public class TouchCollection : List<TouchLocation>
/// </summary>
private bool isConnected;
- //Helpers
- private List<TouchLocation> aux;
-
#region Properties
public bool IsConnected
{
@@ -75,7 +72,6 @@ public bool IsReadOnly
public TouchCollection()
{
- aux = new List<TouchLocation>();
}
internal TouchCollection(IEnumerable<TouchLocation> locations) : base (locations)
@@ -83,16 +79,10 @@ internal TouchCollection(IEnumerable<TouchLocation> locations) : base (locations
}
- public bool Contains(TouchLocation item)
- {
- return (this.IndexOf(item) >= 0);
- }
-
internal void Update()
- {
- //Console.WriteLine("----------------"+this.Count+"--------------------");
- aux.Clear();
- for (int i = 0; i < this.Count; i++)
+ {
+ //Console.WriteLine(">>> Touches: {0}", Count);
+ for (int i = this.Count - 1; i >= 0; --i)
{
TouchLocation t = this[i];
switch (t.State)
@@ -107,36 +97,27 @@ internal void Update()
this[i] = t;
break;
case TouchLocationState.Released:
- aux.Add(t);
+ case TouchLocationState.Invalid:
+ RemoveAt(i);
break;
}
}
- foreach(TouchLocation touch in aux)
- this.Remove(touch);
+ //Console.WriteLine("<<< Touches: {0}", Count);
}
-
- public void CopyTo (TouchLocation[] array, int arrayIndex)
+
+ public bool FindById(int id, out TouchLocation touchLocation)
{
- if (array == null)
+ int index = this.FindIndex((t) => { return t.Id == id; });
+ if (index >= 0)
{
- throw new ArgumentNullException("array");
- }
- if (arrayIndex < 0)
- {
- throw new ArgumentOutOfRangeException("arrayIndex");
- }
- long num = arrayIndex + this.Count;
- if (array.Length < num)
- {
- throw new ArgumentOutOfRangeException("arrayIndex");
- }
- for(int i = 0; i < this.Count; i++)
- {
- array[arrayIndex+i] = this[i];
+ touchLocation = this[index];
+ return true;
}
+ touchLocation = default(TouchLocation);
+ return false;
}
-
- public int FindById(int id, out TouchLocation touchLocation)
+
+ internal int FindIndexById(int id, out TouchLocation touchLocation)
{
for (int i = 0; i < this.Count; i++)
{
@@ -147,22 +128,36 @@ public int FindById(int id, out TouchLocation touchLocation)
return i;
}
}
- touchLocation = new TouchLocation();
+ touchLocation = default(TouchLocation);
return -1;
}
-
-
- public int IndexOf(TouchLocation item)
+
+ internal void Add(int id, Vector2 position) {
+ for (int i = 0; i < Count; i++) {
+ if (this[i].Id == id) {
+ Console.WriteLine("Error: Attempted to re-add the same touch as a press.");
+ Clear ();
+ }
+ }
+ Add(new TouchLocation(id, TouchLocationState.Pressed, position));
+ }
+
+ internal void Update(int id, TouchLocationState state, Vector2 position)
{
- for (int i = 0; i < this.Count; i++)
- {
- if (this[i] == item)
- {
- return i;
+ if (state == TouchLocationState.Pressed)
+ throw new ArgumentException("Argument 'state' cannot be TouchLocationState.Pressed.");
+
+ for (int i = 0; i < Count; i++) {
+ if (this[i].Id == id) {
+ var touchLocation = this[i];
+ touchLocation.Position = position;
+ touchLocation.State = state;
+ this[i] = touchLocation;
+ return;
}
}
- return -1;
+ Console.WriteLine("Error: Attempted to mark a non-existent touch {0} as {1}.", id, state);
+ Clear ();
}
-
}
}
View
6 MonoGame.Framework/MonoGame.Framework.iOS.csproj
@@ -338,7 +338,11 @@
<Compile Include="Net\NetworkMessageType.cs" />
<Compile Include="iOS\GamerServices\SignedInGamer.cs" />
<Compile Include="iOS\Input\GamePad.cs" />
- <Compile Include="iOS\IOSGameWindow.cs" />
+ <Compile Include="iOS\iOSGameWindow.cs" />
+ <Compile Include="GameWindow.cs" />
+ <Compile Include="iOS\iOSGameView.cs" />
+ <Compile Include="iOS\iOSGameView_GLAbstraction.cs" />
+ <Compile Include="iOS\iOSGameView_Touch.cs" />
<Compile Include="iOS\PowerStatus.cs" />
<Compile Include="iOS\Media\MediaSource.cs" />
<Compile Include="iOS\Media\MediaLibrary.cs" />
View
27 MonoGame.Framework/iOS/GamerServices/Guide.cs
@@ -39,12 +39,13 @@ 1. Definitions
#endregion License
#region Using clause
+
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
-using System.Threading;
using System.Runtime.Remoting.Messaging;
+using System.Threading;
using MonoTouch.UIKit;
using MonoTouch.Foundation;
@@ -137,8 +138,12 @@ private static NSObject GetInvokeOnMainThredObj()
return invokeOnMainThredObj;
}
+ private static UIWindow _window;
internal static void Initialise(Game game) {
-
+ _window = (UIWindow)game.Services.GetService(typeof(UIWindow));
+ if (_window == null)
+ throw new InvalidOperationException(
+ "iOSGamePlatform must add the main UIWindow to Game.Services");
}
delegate string ShowKeyboardInputDelegate(
PlayerIndex player,
@@ -372,12 +377,12 @@ public static void ShowLeaderboard()
TouchPanel.EnabledGestures=prevGestures;
};
- if (Window !=null)
+ if (_window != null)
{
if(viewController == null)
{
viewController = new GameVc();
- Window.Add(viewController.View);
+ _window.Add(viewController.View);
viewController.View.Hidden = true;
}
@@ -415,12 +420,12 @@ public static void ShowAchievements()
TouchPanel.EnabledGestures=prevGestures;
};
- if (Window !=null)
+ if (_window != null)
{
if(viewController == null)
{
viewController = new GameVc();
- Window.Add(viewController.View);
+ _window.Add(viewController.View);
viewController.View.Hidden = true;
}
@@ -491,12 +496,12 @@ public static void ShowMatchMaker()
TouchPanel.EnabledGestures=prevGestures;
};
- if (Window !=null)
+ if (_window != null)
{
if(viewController == null)
{
viewController = new GameVc();
- Window.Add(viewController.View);
+ _window.Add(viewController.View);
viewController.View.Hidden = true;
}
@@ -567,12 +572,6 @@ public static bool SimulateTrialMode
simulateTrialMode = value;
}
}
-
- public static GameWindow Window
- {
- get;
- set;
- }
#endregion
}
}
View
705 MonoGame.Framework/iOS/IOSGameWindow.cs
@@ -1,705 +0,0 @@
-#region License
-/*
-Microsoft Public License (Ms-PL)
-XnaTouch - Copyright © 2009 The XnaTouch Team
-
-All rights reserved.
-
-This license governs use of the accompanying software. If you use the software, you accept this license. If you do not
-accept the license, do not use the software.
-
-1. Definitions
-The terms "reproduce," "reproduction," "derivative works," and "distribution" have the same meaning here as under
-U.S. copyright law.
-
-A "contribution" is the original software, or any additions or changes to the software.
-A "contributor" is any person that distributes its contribution under this license.
-"Licensed patents" are a contributor's patent claims that read directly on its contribution.
-
-2. Grant of Rights
-(A) Copyright Grant- Subject to the terms of this license, including the license conditions and limitations in section 3,
-each contributor grants you a non-exclusive, worldwide, royalty-free copyright license to reproduce its contribution, prepare derivative works of its contribution, and distribute its contribution or any derivative works that you create.
-(B) Patent Grant- Subject to the terms of this license, including the license conditions and limitations in section 3,
-each contributor grants you a non-exclusive, worldwide, royalty-free license under its licensed patents to make, have made, use, sell, offer for sale, import, and/or otherwise dispose of its contribution in the software or derivative works of the contribution in the software.
-
-3. Conditions and Limitations
-(A) No Trademark License- This license does not grant you rights to use any contributors' name, logo, or trademarks.
-(B) If you bring a patent claim against any contributor over patents that you claim are infringed by the software,
-your patent license from such contributor to the software ends automatically.
-(C) If you distribute any portion of the software, you must retain all copyright, patent, trademark, and attribution
-notices that are present in the software.
-(D) If you distribute any portion of the software in source code form, you may do so only under this license by including
-a complete copy of this license with your distribution. If you distribute any portion of the software in compiled or object
-code form, you may only do so under a license that complies with this license.
-(E) The software is licensed "as-is." You bear the risk of using it. The contributors give no express warranties, guarantees
-or conditions. You may have additional consumer rights under your local laws which this license cannot change. To the extent
-permitted under your local laws, the contributors exclude the implied warranties of merchantability, fitness for a particular
-purpose and non-infringement.
-*/
-#endregion License
-
-#region Using Statements
-using System;
-using System.Drawing;
-using System.Collections.Generic;
-
-using MonoTouch.CoreAnimation;
-using MonoTouch.Foundation;
-using MonoTouch.ObjCRuntime;
-using MonoTouch.OpenGLES;
-using MonoTouch.UIKit;
-
-using OpenTK.Platform.iPhoneOS;
-
-using OpenTK;
-using OpenTK.Platform;
-using OpenTK.Graphics;
-using OpenTK.Graphics.ES11;
-using OpenTK.Graphics.ES20;
-
-using Microsoft.Xna.Framework.Input;
-using Microsoft.Xna.Framework.Input.Touch;
-using Microsoft.Xna.Framework.Graphics;
-#endregion Using Statements
-
-namespace Microsoft.Xna.Framework
-{
- public class GameWindow : iPhoneOSGameView
- {
- private readonly Rectangle clientBounds;
- private iOSGamePlatform _platform;
- private GameTime _updateGameTime;
- private GameTime _drawGameTime;
- private DateTime _lastUpdate;
- private DateTime _lastDraw;
- private DateTime _nowUpdate;
- private DateTime _nowDraw;
-
- // HACK HACK HACK!
- /// <summary>
- /// This is an amazing hack that is based on the knowledge that Run will call CreateFrameBuffer
- /// and that Stop will call DestroyFrameBuffer. We don't want to do either (we don't want to touch
- /// the OpenGL state while the application is being backgrounded/foregrounded). So when the application
- /// is pausing (from DidEnterBackground) simply don't allow CreateFrameBuffer or DestroyFrameBuffer to run.
- /// Also OnLoad, the Load event, OnUnload and the Unload event are called - assume they pose no problem
- /// (although the same technique could be used if they do).
- ///
- /// The reason that Run and Stop need to be called at all is to stop the timer that is dispatching
- /// update and draw events (which will touch the OpenGL context and get us killed when backgrounded).
- /// </summary>
- bool isPausing = false;
-
- UITapGestureRecognizer recognizerTap;
- UITapGestureRecognizer recognizerDoubleTap;
- UIPinchGestureRecognizer recognizerPinch;
-
- // As per http://stackoverflow.com/questions/3319209/setting-direction-for-uiswipegesturerecognizer
- UISwipeGestureRecognizer recognizerLeftRightSwipe;
- UISwipeGestureRecognizer recognizerUpDownSwipe;
-
- UILongPressGestureRecognizer recognizerLongPress;
- UIPanGestureRecognizer recognizerPan;
- UIRotationGestureRecognizer recognizerRotation;
-
- Vector2 translatedTouchPosition;
-
- public EAGLContext MainContext;
- public EAGLContext BackgroundContext;
- public EAGLSharegroup ShareGroup;
-
- #region UIVIew Methods
-
- internal GameWindow(iOSGamePlatform platform) : base (UIScreen.MainScreen.Bounds)
- {
- if (platform == null)
- throw new ArgumentNullException("platform");
- _platform = platform;
-
- LayerRetainsBacking = false;
- LayerColorFormat = EAGLColorFormat.RGBA8;
- ContentScaleFactor = UIScreen.MainScreen.Scale;
-
- RectangleF rect = UIScreen.MainScreen.Bounds;
- clientBounds = new Rectangle(0,0,(int) (rect.Width * UIScreen.MainScreen.Scale),(int) (rect.Height * UIScreen.MainScreen.Scale));
-
- // Enable multi-touch
- MultipleTouchEnabled = true;
-
- // Don't Autoresize, we'll do that
- AutoResize = false;
-
- // Initialize GameTime
- _updateGameTime = new GameTime();
- _drawGameTime = new GameTime();
-
- // Initialize _lastUpdate and _lastDraw
- _lastUpdate = DateTime.Now;
- _lastDraw = DateTime.Now;
- }
-
- ~GameWindow()
- {
- //
- }
-
- [Export ("layerClass")]
- static Class LayerClass()
- {
- return iPhoneOSGameView.GetLayerClass ();
- }
-
- public override bool CanBecomeFirstResponder
- {
- get { return true; }
- }
-
- protected override void ConfigureLayer(CAEAGLLayer eaglLayer)
- {
- eaglLayer.Opaque = true;
-
- // Scale OpenGL layer to the scale of the main layer
- // On iPhone 4 this makes the renderbuffer size the same as actual device resolution
- // On iPad with user-selected scale of 2x at startup, this will trigger but has no effect on the renderbuffer
- if(UIScreen.MainScreen.Scale != 1)
- eaglLayer.ContentsScale = UIScreen.MainScreen.Scale;
- }
-
- int renderbufferWidth;
- int renderbufferHeight;
-
- protected override void CreateFrameBuffer()
- {
- if(isPausing)
- return; // See note on isPausing
-#if !TEST1_1
- try
- {
- ContextRenderingApi = EAGLRenderingAPI.OpenGLES2;
- base.CreateFrameBuffer();
-
- unsafe
- {
- int width = 0, height = 0;
- OpenTK.Graphics.ES20.GL.GetRenderbufferParameter(OpenTK.Graphics.ES20.All.Renderbuffer, OpenTK.Graphics.ES20.All.RenderbufferWidth, &width);
- OpenTK.Graphics.ES20.GL.GetRenderbufferParameter(OpenTK.Graphics.ES20.All.Renderbuffer, OpenTK.Graphics.ES20.All.RenderbufferHeight, &height);
-
- renderbufferWidth = width;
- renderbufferHeight = height;
- }
- }
- catch (Exception)
-#endif
- {
- // device doesn't support OpenGLES 2.0; retry with 1.1:
- ContextRenderingApi = EAGLRenderingAPI.OpenGLES1;
- base.CreateFrameBuffer();
-
- // Determine actual render buffer size (due to possible Retina Display scaling)
- // http://developer.apple.com/library/ios/#documentation/iphone/conceptual/iphoneosprogrammingguide/SupportingResolutionIndependence/SupportingResolutionIndependence.html#//apple_ref/doc/uid/TP40007072-CH10-SW11
- unsafe
- {
- int width = 0, height = 0;
- OpenTK.Graphics.ES11.GL.Oes.GetRenderbufferParameter(OpenTK.Graphics.ES11.All.RenderbufferOes, OpenTK.Graphics.ES11.All.RenderbufferWidthOes, &width);
- OpenTK.Graphics.ES11.GL.Oes.GetRenderbufferParameter(OpenTK.Graphics.ES11.All.RenderbufferOes, OpenTK.Graphics.ES11.All.RenderbufferHeightOes, &height);
-
- renderbufferWidth = width;
- renderbufferHeight = height;
- }
- }
-
- // OpenGL Version for GraphicsDevice (Used to generate OpenGL1.1 or Opengl2.0 textures, buffers, and draw with Fixed or Fragment Pixel Shader)
- //GraphicsDevice.OpenGLESVersion = ContextRenderingApi;
- if (_platform.Game.GraphicsDevice != null)
- _platform.Game.GraphicsDevice.glFramebuffer = this.Framebuffer;
- }
-
- protected override void DestroyFrameBuffer()
- {
- if(isPausing)
- return; // see note on isPausing
-
- base.DestroyFrameBuffer();
- }
-
- public void Pause()
- {
- isPausing = true;
- Stop();
- }
-
- public void Resume()
- {
- Run();
- isPausing = false;
- }
-
- #endregion
-
- #region iPhoneOSGameView Methods
-
- protected override void OnClosed(EventArgs e)
- {
- base.OnClosed(e);
- TouchPanel.EnabledGesturesChanged -= updateGestures;
- }
-
- protected override void OnDisposed(EventArgs e)
- {
- base.OnDisposed(e);
- }
-
- protected override void OnLoad (EventArgs e)
- {
- base.OnLoad(e);
- updateGestures (null, null);
- TouchPanel.EnabledGesturesChanged += updateGestures;
- }
-
- void updateGestures (object sender, EventArgs e)
- {
- var enabledGestures = TouchPanel.EnabledGestures;
-
- if ((enabledGestures & GestureType.Hold) != 0)
- {
- if (recognizerLongPress == null)
- {
- recognizerLongPress = new UILongPressGestureRecognizer(this, new Selector("LongPressGestureRecognizer"));
- recognizerLongPress.MinimumPressDuration = 1.0;
- AddGestureRecognizer(recognizerLongPress);
- }
- }
- else if (recognizerLongPress != null)
- {
- RemoveGestureRecognizer(recognizerLongPress);
- recognizerLongPress = null;
- }
-
- if ((enabledGestures & GestureType.Tap) != 0)
- {
- if (recognizerTap == null)
- {
- recognizerTap = new UITapGestureRecognizer(this, new Selector("TapGestureRecognizer"));
- recognizerTap.NumberOfTapsRequired = 1;
- AddGestureRecognizer(recognizerTap);
- }
- }
- else if (recognizerTap != null)
- {
- RemoveGestureRecognizer(recognizerTap);
- recognizerTap = null;
- }
-
- if ((enabledGestures & GestureType.DoubleTap) != 0)
- {
- if (recognizerDoubleTap == null)
- {
- recognizerDoubleTap = new UITapGestureRecognizer(this, new Selector("TapGestureRecognizer"));
- recognizerDoubleTap.NumberOfTapsRequired = 2;
- AddGestureRecognizer(recognizerDoubleTap);
- }
- }
- else if (recognizerDoubleTap != null)
- {
- RemoveGestureRecognizer(recognizerDoubleTap);
- recognizerDoubleTap = null;
- }
-
- if ((enabledGestures & GestureType.FreeDrag) != 0)
- {
- if (recognizerPan == null)
- {
- recognizerPan = new UIPanGestureRecognizer(this, new Selector("PanGestureRecognizer"));
- recognizerPan.CancelsTouchesInView = false;
- AddGestureRecognizer(recognizerPan);
- }
- }
- else if (recognizerPan != null)
- {
- RemoveGestureRecognizer(recognizerPan);
- recognizerPan = null;
- }
-
- if ((enabledGestures & GestureType.Flick) != 0)
- {
- if (recognizerLeftRightSwipe == null)
- {
- recognizerLeftRightSwipe = new UISwipeGestureRecognizer(this, new Selector("SwipeGestureRecognizer"));
- recognizerLeftRightSwipe.Direction = UISwipeGestureRecognizerDirection.Down | UISwipeGestureRecognizerDirection.Up | UISwipeGestureRecognizerDirection.Left | UISwipeGestureRecognizerDirection.Right;
- AddGestureRecognizer(recognizerLeftRightSwipe);
- }
-
- if (recognizerUpDownSwipe == null)
- {
- recognizerUpDownSwipe = new UISwipeGestureRecognizer(this, new Selector("SwipeGestureRecognizer"));
- recognizerUpDownSwipe.Direction = UISwipeGestureRecognizerDirection.Left | UISwipeGestureRecognizerDirection.Right;
- AddGestureRecognizer(recognizerUpDownSwipe);
- }
- }
- else if (recognizerLeftRightSwipe != null)
- {
- RemoveGestureRecognizer(recognizerLeftRightSwipe);
- recognizerLeftRightSwipe = null;
- }
-
- if ((enabledGestures & GestureType.Flick) != 0)
- {
- if (recognizerUpDownSwipe == null)
- {
- recognizerUpDownSwipe = new UISwipeGestureRecognizer(this, new Selector("SwipeGestureRecognizer"));
- recognizerUpDownSwipe.Direction = UISwipeGestureRecognizerDirection.Up | UISwipeGestureRecognizerDirection.Down;
- AddGestureRecognizer(recognizerUpDownSwipe);
- }
- }
- else if (recognizerUpDownSwipe != null)
- {
- RemoveGestureRecognizer(recognizerUpDownSwipe);
- recognizerUpDownSwipe = null;
- }
-
- if ((enabledGestures & GestureType.Pinch) != 0)
- {
- if (recognizerPinch == null)
- {
- recognizerPinch = new UIPinchGestureRecognizer(this, new Selector("PinchGestureRecognizer"));
- AddGestureRecognizer(recognizerPinch);
- }
- }
- else if (recognizerPinch != null)
- {
- RemoveGestureRecognizer(recognizerPinch);
- recognizerPinch = null;
- }
-
- if ((enabledGestures & GestureType.Rotation) != 0)
- {
- if (recognizerRotation == null)
- {
- recognizerRotation = new UIRotationGestureRecognizer(this, new Selector("RotationGestureRecognizer"));
- AddGestureRecognizer(recognizerRotation);
- }
- }
- else if (recognizerRotation != null)
- {
- RemoveGestureRecognizer(recognizerRotation);
- recognizerRotation = null;
- }
-
- }
-
- protected override void OnRenderFrame(FrameEventArgs e)
- {
- base.OnRenderFrame(e);
-
- MakeCurrent();
-
- // This code was commented to make the code base more iPhone like.
- // More speed testing is required, to see if this is worse or better
- // game.DoStep();
-
- _nowDraw = DateTime.Now;
- _drawGameTime.Update(_nowDraw - _lastDraw);
- _lastDraw = _nowDraw;
- _platform.Game.DoDraw(_drawGameTime);
-
- SwapBuffers();
- }
-
- protected override void OnResize(EventArgs e)
- {
- base.OnResize(e);
- }
-
- protected override void OnTitleChanged(EventArgs e)
- {
- base.OnTitleChanged(e);
- }
-
- protected override void OnUnload(EventArgs e)
- {
- base.OnUnload(e);
- }
-
- protected override void OnUpdateFrame(FrameEventArgs e)
- {
- base.OnUpdateFrame(e);
-
- _nowUpdate = DateTime.Now;
- _updateGameTime.Update(_nowUpdate - _lastUpdate);
- _lastUpdate = _nowUpdate;
- _platform.Game.DoUpdate(_updateGameTime);
- }
-
- protected override void OnVisibleChanged(EventArgs e)
- {
- base.OnVisibleChanged(e);
- }
-
- protected override void OnWindowStateChanged(EventArgs e)
- {
- base.OnWindowStateChanged(e);
- }
-
- #endregion
-
- #region UIVIew Methods
-
- [Export("LongPressGestureRecognizer")]
- public void LongPressGestureRecognizer (UILongPressGestureRecognizer sender)
- {
- // FIXME: Determine the appropriate action to take here. The XNA
- // docs say, "This is a single event, and not continuously
- // generated while the user is holding the touchpoint."
- // However, iOS generates Began for that condition, then zero
- // or more Changed notifications, and then one of the final-
- // state notifications (Recognized, Failed, etc)
- if (sender.State == UIGestureRecognizerState.Began)
- {
- var point = sender.LocationInView(sender.View);
- TouchPanel.GestureList.Enqueue(new GestureSample(GestureType.Hold, new TimeSpan(_nowUpdate.Ticks), translatedTouchPosition, new Vector2 (point.X, point.Y), new Vector2(0,0), new Vector2(0,0)));
- }
- }
-
-
- [Export("PanGestureRecognizer")]
- public void PanGestureRecognizer (UIPanGestureRecognizer sender)
- {
- var point = sender.LocationInView(sender.View);
- if (sender.State==UIGestureRecognizerState.Ended || sender.State==UIGestureRecognizerState.Cancelled || sender.State==UIGestureRecognizerState.Failed)
- TouchPanel.GestureList.Enqueue(new GestureSample(GestureType.DragComplete, new TimeSpan(_nowUpdate.Ticks), translatedTouchPosition, new Vector2(0,0), new Vector2 (point.X, point.Y), new Vector2(0,0)));
- else
- TouchPanel.GestureList.Enqueue(new GestureSample(GestureType.FreeDrag, new TimeSpan(_nowUpdate.Ticks), translatedTouchPosition, new Vector2(0,0), new Vector2 (point.X, point.Y), new Vector2(0,0)));
- }
-
- [Export("PinchGestureRecognizer")]
- public void PinchGestureRecognizer (UIPinchGestureRecognizer sender)
- {
- var point0 = sender.LocationOfTouch(0, sender.View);
- var point1 = sender.LocationOfTouch(1, sender.View);
- TouchPanel.GestureList.Enqueue(new GestureSample(GestureType.Pinch, new TimeSpan(_nowUpdate.Ticks), new Vector2 (point0.X, point0.Y), new Vector2 (point1.X, point1.Y), new Vector2(0,0), new Vector2(0,0)));
- }
-
-
- [Export("RotationGestureRecognizer")]
- public void RotationGestureRecognizer (UIRotationGestureRecognizer sender)
- {
- var point0 = sender.LocationOfTouch(0, sender.View);
- var point1 = sender.LocationOfTouch(1, sender.View);
- TouchPanel.GestureList.Enqueue(new GestureSample(GestureType.Rotation, new TimeSpan(_nowUpdate.Ticks), new Vector2 (point0.X, point0.Y), new Vector2 (point1.X, point1.Y), new Vector2(0,0), new Vector2(0,0)));
- }
-
- [Export("SwipeGestureRecognizer")]
- public void SwipeGestureRecognizer (UISwipeGestureRecognizer sender)
- {
- var point = sender.LocationInView(sender.View);
- TouchPanel.GestureList.Enqueue(new GestureSample(GestureType.Flick, new TimeSpan(_nowUpdate.Ticks), new Vector2 (point.X, point.Y), new Vector2 (point.X, point.Y), new Vector2(0,0), new Vector2(0,0)));
- }
-
- [Export("TapGestureRecognizer")]
- public void TapGestureRecognizer (UITapGestureRecognizer sender)
- {
- var point = sender.LocationInView(sender.View);
- TouchPanel.GestureList.Enqueue(new GestureSample(GestureType.Tap, new TimeSpan(_nowUpdate.Ticks), translatedTouchPosition, new Vector2 (point.X, point.Y), new Vector2(0,0), new Vector2(0,0)));
- }
-
- private void FillTouchCollection(NSSet touches)
- {
- UITouch []touchesArray = touches.ToArray<UITouch>();
-
- for (int i=0; i < touchesArray.Length;i++)
- {
-
- //Get IOS touch
- UITouch touch = touchesArray[i];
-
- //Get position touch
- var point = touch.LocationInView(touch.View);
- Vector2 position = new Vector2 (point.X, point.Y);
- translatedTouchPosition = GetOffsetPosition(position, true);
-
- TouchLocation tlocation;
- TouchCollection collection = TouchPanel.Collection;
- int index;
- switch (touch.Phase)
- {
- case UITouchPhase.Stationary:
- case UITouchPhase.Moved:
- index = collection.FindById(touch.Handle.ToInt32(), out tlocation);
- if (index >= 0)
- {
- tlocation.State = TouchLocationState.Moved;
- tlocation.Position = translatedTouchPosition;
- collection[index] = tlocation;
- }
-
- if (i == 0)
- {
- Mouse.State.X = (int)translatedTouchPosition.X;
- Mouse.State.Y = (int)translatedTouchPosition.Y;
- }
- break;
- case UITouchPhase.Began :
- tlocation = new TouchLocation(touch.Handle.ToInt32(), TouchLocationState.Pressed, translatedTouchPosition);
- collection.Add(tlocation);
- if (i == 0)
- {
- Mouse.State.X = (int)translatedTouchPosition.X;
- Mouse.State.Y = (int)translatedTouchPosition.Y;
- Mouse.State.LeftButton = ButtonState.Pressed;
- }
- break;
- case UITouchPhase.Ended :
- index = collection.FindById(touch.Handle.ToInt32(), out tlocation);
- if (index >= 0)
- {
- tlocation.State = TouchLocationState.Released;
- collection[index] = tlocation;
- }
-
- if (i == 0)
- {
- Mouse.State.X = (int)translatedTouchPosition.X;
- Mouse.State.Y = (int)translatedTouchPosition.Y;
- Mouse.State.LeftButton = ButtonState.Released;
- }
- break;
- case UITouchPhase.Cancelled:
- index = collection.FindById(touch.Handle.ToInt32(), out tlocation);
- if (index >= 0)
- {
- tlocation.State = TouchLocationState.Invalid;
- collection[index] = tlocation;
- }
- break;
- default :
- break;
- }
- }
- }
-
- internal Vector2 GetOffsetPosition(Vector2 position, bool useScale)
- {
- Vector2 translatedPosition = position * UIScreen.MainScreen.Scale;
-
- switch (CurrentOrientation)
- {
- case DisplayOrientation.Portrait :
- {
- break;
- }
-
- case DisplayOrientation.LandscapeRight :
- {
- translatedPosition = new Vector2( ClientBounds.Height - translatedPosition.Y, translatedPosition.X );
- break;
- }
-
- case DisplayOrientation.LandscapeLeft :
- {
- translatedPosition = new Vector2( translatedPosition.Y, ClientBounds.Width - translatedPosition.X );
- break;
- }
-
- case DisplayOrientation.PortraitUpsideDown :
- {
- translatedPosition = new Vector2( ClientBounds.Width - translatedPosition.X, ClientBounds.Height - translatedPosition.Y );
- break;
- }
- }
- if(!useScale)
- translatedPosition = translatedPosition / UIScreen.MainScreen.Scale;
- return translatedPosition;
- }
-
- public override void TouchesBegan (NSSet touches, UIEvent evt)
- {
- base.TouchesBegan (touches, evt);
-
- FillTouchCollection(touches);
-
- GamePad.Instance.TouchesBegan(touches,evt,this);
- }
-
- public override void TouchesEnded (NSSet touches, UIEvent evt)
- {
- base.TouchesEnded (touches, evt);
-
- FillTouchCollection(touches);
-
- GamePad.Instance.TouchesEnded(touches,evt,this);
- }
-
- public override void TouchesMoved (NSSet touches, UIEvent evt)
- {
- base.TouchesMoved (touches, evt);
-
- FillTouchCollection(touches);
-
- GamePad.Instance.TouchesMoved(touches,evt,this);
- }
-
- public override void TouchesCancelled (NSSet touches, UIEvent evt)
- {
- base.TouchesCancelled (touches, evt);
-
- FillTouchCollection(touches);
-
- GamePad.Instance.TouchesCancelled(touches,evt);
- }
-
- #endregion
-
- public string ScreenDeviceName
- {
- get
- {
- throw new System.NotImplementedException ();
- }
- }
-
- public Rectangle ClientBounds
- {
- get
- {
- return clientBounds;
- }
- }
-
- public bool AllowUserResizing
- {
- get
- {
- return false;
- }
- set
- {
- // Do nothing; Ignore rather than raising and exception
- }
- }
-
- private DisplayOrientation _currentOrientation;
- public DisplayOrientation CurrentOrientation
- {
- get
- {
- return _currentOrientation;
- }
- internal set
- {
- if (value != _currentOrientation)
- {
- _currentOrientation = value;
- if (OrientationChanged != null)
- {
- OrientationChanged(this, EventArgs.Empty);
- }
-
- }
- }
- }
-
- public event EventHandler<EventArgs> OrientationChanged;
- public event EventHandler ClientSizeChanged;
- public event EventHandler ScreenDeviceNameChanged;
- }
-}
-
View
14 MonoGame.Framework/iOS/Input/GamePad.cs
@@ -186,7 +186,7 @@ private bool CheckThumbStickHit(ThumbStickDefinition theStick, Vector2 location)
return thumbRect.Contains(location);
}
- internal void TouchesBegan( MonoTouch.Foundation.NSSet touches, MonoTouch.UIKit.UIEvent e, GameWindow window)
+ internal void TouchesBegan( MonoTouch.Foundation.NSSet touches, MonoTouch.UIKit.UIEvent e, iOSGameView view)
{
// Reset State
//Reset();
@@ -197,7 +197,8 @@ internal void TouchesBegan( MonoTouch.Foundation.NSSet touches, MonoTouch.UIKit.
{
var point = touch.LocationInView(touch.View);
Vector2 location = new Vector2(point.X, point.Y);
- location = window.GetOffsetPosition(location,false);
+ location = view.GetOffsetPosition(location, true);
+
// Check where is the touch
bool hitInButton = false;
@@ -241,14 +242,14 @@ internal void TouchesCancelled( MonoTouch.Foundation.NSSet touches, MonoTouch.UI
// do nothing
}
- internal void TouchesMoved( MonoTouch.Foundation.NSSet touches, MonoTouch.UIKit.UIEvent e,GameWindow window)
+ internal void TouchesMoved( MonoTouch.Foundation.NSSet touches, MonoTouch.UIKit.UIEvent e, iOSGameView view)
{
UITouch []touchesArray = touches.ToArray<UITouch>();
foreach(UITouch touch in touchesArray)
{
var point = touch.LocationInView(touch.View);
Vector2 location = new Vector2(point.X, point.Y);
- location = window.GetOffsetPosition(location,false);
+ location = view.GetOffsetPosition(location, true);
var oldItem = GetTouchesObject(touch);
// Check if touch any button
@@ -350,14 +351,15 @@ internal void TouchesMoved( MonoTouch.Foundation.NSSet touches, MonoTouch.UIKit.
}
}
- internal void TouchesEnded( MonoTouch.Foundation.NSSet touches, MonoTouch.UIKit.UIEvent e, GameWindow window)
+ internal void TouchesEnded( MonoTouch.Foundation.NSSet touches, MonoTouch.UIKit.UIEvent e, iOSGameView view)
{
UITouch []touchesArray = touches.ToArray<UITouch>();
foreach(UITouch touch in touchesArray)
{
var point = touch.LocationInView(touch.View);
Vector2 location = new Vector2(point.X, point.Y);
- location = window.GetOffsetPosition(location,false);
+ location = view.GetOffsetPosition(location, true);
+
// Check where is the touch
if (Visible)
{
View
4 MonoGame.Framework/iOS/Media/VideoPlayer.cs
@@ -92,8 +92,6 @@ private void PlayVideo()
_video.MovieView.MoviePlayer.RepeatMode = _isLooped ? MPMovieRepeatMode.One : MPMovieRepeatMode.None;
- // HACK: Pause window to prevent GL context re-creation.
- _platform.Window.Pause();
_platform.ViewController.PresentModalViewController(_video.MovieView, animated: false);
_video.MovieView.MoviePlayer.Play();
}
@@ -121,8 +119,6 @@ public void Stop()
_state = MediaState.Stopped;
_platform.IsPlayingVideo = false;
_platform.ViewController.DismissModalViewControllerAnimated(false);
- // HACK: End of pausing to prevent GL context re-creation.
- _platform.Window.Resume();
}
public bool IsLooped
View
166 MonoGame.Framework/iOS/iOSGamePlatform.cs
@@ -70,29 +70,24 @@ 1. Definitions
using System.Collections.Generic;
using System.IO;
-using Microsoft.Xna.Framework.Input;
-using Microsoft.Xna.Framework.Input.Touch;
-
using MonoTouch.Foundation;
using MonoTouch.OpenGLES;
using MonoTouch.UIKit;
+
using Microsoft.Xna.Framework.Audio;
+using Microsoft.Xna.Framework.Input;
+using Microsoft.Xna.Framework.Input.Touch;
namespace Microsoft.Xna.Framework
{
class iOSGamePlatform : GamePlatform
{
- // FIXME: Previously components were being initialized on a background thread, apparently. We may need to
- // express this concept somewhere within the Game-GamePlatform contract. Not sure where yet.
-// EAGLContext.SetCurrentContext(_window.BackgroundContext);
-// Initialize all components...
-// EAGLContext.SetCurrentContext(_window.MainContext);
-
private iOSGameViewController _viewController;
private UIWindow _mainWindow;
- private NSObject _rotationObserver;
private List<NSObject> _applicationObservers;
private OpenALSoundController soundControllerInstance = null;
+ private NSTimer _runTimer;
+ private bool _isExitPending;
public iOSGamePlatform(Game game) :
base(game)
@@ -108,13 +103,14 @@ class iOSGamePlatform : GamePlatform
// Create a full-screen window
_mainWindow = new UIWindow(UIScreen.MainScreen.Bounds);
+ game.Services.AddService(typeof(UIWindow), _mainWindow);
_viewController = new iOSGameViewController(this);
- _viewController.View.Load += GameWindow_Load;
- _viewController.View.Unload += GameWindow_Unload;
- Window = _viewController.View;
+ _viewController.InterfaceOrientationChanged += ViewController_InterfaceOrientationChanged;
+ Window = new iOSGameWindow(_viewController);
_mainWindow.RootViewController = _viewController;
+ _mainWindow.Add (_viewController.View);
}
public override GameRunBehavior DefaultRunBehavior
@@ -122,6 +118,9 @@ public override GameRunBehavior DefaultRunBehavior
get { return GameRunBehavior.Asynchronous; }
}
+ [Obsolete(
+ "iOSGamePlatform.IsPlayingVideo must be removed when MonoGame " +
+ "fully implements the XNA VideoPlayer contract.")]
public bool IsPlayingVideo { get; set; }
// FIXME: VideoPlayer 'needs' this to set up its own movie player view
@@ -136,31 +135,27 @@ protected override void Dispose(bool disposing)
base.Dispose(disposing);
if (disposing)
{
- if (_mainWindow != null)
- {
- _mainWindow.Dispose();
- _mainWindow = null;
- }
if (_viewController != null)
{
+ _viewController.View.RemoveFromSuperview ();
+ _viewController.RemoveFromParentViewController ();
_viewController.Dispose();
_viewController = null;
}
+
+ if (_mainWindow != null)
+ {
+ _mainWindow.Dispose();
+ _mainWindow = null;
+ }
}
}
public override void BeforeInitialize()
{
+ base.BeforeInitialize ();
+ _viewController.View.MakeCurrent ();
TouchPanel.Reset();
-
- // HACK: Force the OpenGL context to be created before any
- // components are initialized. This hack could be eliminated
- // by implementing a custom Initialize method in
- // iOSGameWindow that calls CreateFrameBuffer and OnLoad.
- // CreateFrameBuffer and OnLoad would both need to be changed
- // to be idempotent per create-destroy cycle of the OpenGL
- // context.
- _viewController.View.Run(1.0 / Game.TargetElapsedTime.TotalSeconds);
}
public override void RunLoop()
@@ -175,31 +170,54 @@ public override void StartRunLoop()
Accelerometer.SetupAccelerometer();
BeginObservingUIApplication();
- BeginObservingDeviceRotation();
_viewController.View.BecomeFirstResponder();
+ _runTimer = NSTimer.CreateRepeatingScheduledTimer(Game.TargetElapsedTime, Tick);
}
- private void GameWindow_Load(object sender, EventArgs e)
+ private void Tick()
{
- // FIXME: Surely this activity should be performed by some other
- // class. iOSGameViewController or the iOS GameWindow.
- _viewController.View.MainContext = _viewController.View.EAGLContext;
- _viewController.View.ShareGroup = _viewController.View.MainContext.ShareGroup;
- _viewController.View.BackgroundContext = new EAGLContext(_viewController.View.ContextRenderingApi, _viewController.View.ShareGroup);
- Threading.BackgroundContext = _viewController.View.BackgroundContext;
+ try {
+ if (PerformPendingExit())
+ return;
+ if (IsPlayingVideo)
+ return;
+
+ // FIXME: Remove this call, and the whole Tick method, once
+ // GraphicsDevice is where platform-specific Present
+ // functionality is actually implemented. At that
+ // point, it should be possible to pass Game.Tick directly
+ // to NSTimer.CreateRepeatingTimer.
+ _viewController.View.MakeCurrent();
+ Game.Tick ();
+
+ if (!IsPlayingVideo)
+ _viewController.View.Present ();
+
+ PerformPendingExit();
+ } catch (Exception ex) {
+ Console.WriteLine(
+ "Error while processing the main game loop: {0}\n{1}",
+ ex.Message, ex.StackTrace);
+ Game.Exit ();
+ }
}
- private void GameWindow_Unload(object sender, EventArgs e)
+ private bool PerformPendingExit()
{
- // FIXME: Surely this activity should be performed by some other
- // class. iOSGameViewController or the iOS GameWindow.
- _viewController.View.MainContext = null;
- _viewController.View.ShareGroup = null;
- // FIXME: Dispose BackgroundContext first? We created it in
- // GameWindow_Load.
- _viewController.View.BackgroundContext = null;
- }
+ if (!_isExitPending)
+ return false;
+
+ _isExitPending = false;
+ if (_runTimer != null) {
+ _runTimer.Invalidate ();
+ _runTimer.Dispose ();
+ _runTimer = null;
+ }
+ StopObservingUIApplication ();
+ RaiseAsyncRunLoopEnded ();
+ return true;
+ }
public override bool BeforeDraw(GameTime gameTime)
{
@@ -229,12 +247,7 @@ public override void ExitFullScreen()
public override void Exit()
{
- StopObservingUIApplication();
- StopObservingDeviceRotation();
- // FIXME: Need to terminate the run loop. On iOS, this probably means
- // destroying _mainWindow. But should async platforms try to kill the
- // whole program?
- //throw new NotImplementedException();
+ _isExitPending = true;
}
private void BeginObservingUIApplication()
@@ -271,21 +284,6 @@ private void StopObservingUIApplication()
_applicationObservers.Clear();
}
- private void BeginObservingDeviceRotation()
- {
- _rotationObserver = NSNotificationCenter.DefaultCenter.AddObserver(
- new NSString("UIDeviceOrientationDidChangeNotification"),
- Device_OrientationDidChange);
-
- UIDevice.CurrentDevice.BeginGeneratingDeviceOrientationNotifications();
- }
-
- private void StopObservingDeviceRotation()
- {
- NSNotificationCenter.DefaultCenter.RemoveObserver(_rotationObserver);
- UIDevice.CurrentDevice.EndGeneratingDeviceOrientationNotifications();
- }
-
#region Notification Handling
private void Application_WillEnterForeground(NSNotification notification)
@@ -325,49 +323,33 @@ private void Application_DidReceiveMemoryWarning(NSNotification notification)
GC.Collect();
}
- private void Device_OrientationDidChange(NSNotification notification)
+ #endregion Notification Handling
+
+ private void ViewController_InterfaceOrientationChanged (object sender, EventArgs e)
{
- var orientation = OrientationConverter.UIDeviceOrientationToDisplayOrientation(
- UIDevice.CurrentDevice.Orientation);
+ var orientation = OrientationConverter.ToDisplayOrientation (
+ _viewController.InterfaceOrientation);
- // Calculate supported orientations if it has been left as "default"
- var gdm = (GraphicsDeviceManager)Game.Services.GetService(typeof(IGraphicsDeviceManager));
- DisplayOrientation supportedOrientations = gdm.SupportedOrientations;
+ // FIXME: The presentation parameters for the GraphicsDevice should
+ // be managed by the GraphicsDevice itself. Not by
+ // iOSGamePlatform.
+ var gdm = (GraphicsDeviceManager) Game.Services.GetService (typeof (IGraphicsDeviceManager));
+ if (gdm != null) {
var presentParams = gdm.GraphicsDevice.PresentationParameters;
-
- if (presentParams.BackBufferWidth != gdm.PreferredBackBufferWidth)
presentParams.BackBufferWidth = gdm.PreferredBackBufferWidth;
-
- if (presentParams.BackBufferHeight != gdm.PreferredBackBufferHeight)
presentParams.BackBufferHeight = gdm.PreferredBackBufferHeight;
-
- if ((supportedOrientations & DisplayOrientation.Default) != 0)
- {
- if (presentParams.BackBufferWidth > presentParams.BackBufferHeight)
- supportedOrientations = DisplayOrientation.LandscapeLeft | DisplayOrientation.LandscapeRight;
- else
- supportedOrientations = DisplayOrientation.Portrait | DisplayOrientation.PortraitUpsideDown;
- }
-
- if ((supportedOrientations & orientation) == orientation)
- {
- _viewController.View.CurrentOrientation = orientation;
presentParams.DisplayOrientation = orientation;
- TouchPanel.DisplayOrientation = orientation;
}
+ TouchPanel.DisplayOrientation = orientation;
}
- #endregion Notification Handling
public override void BeginScreenDeviceChange (bool willBeFullScreen)
{
-
}
public override void EndScreenDeviceChange (string screenDeviceName, int clientWidth,int clientHeight)
{
-
}
}
}
-
View
635 MonoGame.Framework/iOS/iOSGameView.cs
@@ -1,283 +1,352 @@
-using System;
-using System.ComponentModel;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-
-using MonoTouch.UIKit;
-
-using OpenTK;
-using OpenTK.Platform;
-
-namespace Microsoft.Xna.Framework
-{
- public class iOSGameView : UIViewController//, IGameWindow
- {
- public iOSGameView()
- {
-
- }
-
- public override void ViewWillAppear(bool animated)
- {
- // Prepare to start the game appear
- base.ViewWillAppear(animated);
- }
-
- public override void ViewDidAppear(bool animated)
- {
- // Start the game loop
- base.ViewDidAppear(animated);
- }
-
- public override void ViewWillDisappear(bool animated)
- {
- // Prepare to pause the game
- base.ViewWillDisappear(animated);
- }
-
- public override void ViewDidDisappear(bool animated)
- {
- // Pause the game loop
- base.ViewWillDisappear(animated);
- }
-
- // NSTimer will cause latency in rendering and may reduce frame rate.
- //iOS 4 onwards...
- // public CADisplaLink DisplayLinkWithTarget
-
- // Called whenever the bounds of the view changes
- /* public override void LayoutSubviews()
- {
- // deleteFrameBuffer
-
- // createFrameBuffer at the right size
- }*/
-
- // Copied from your game stuff Clancey
- public override bool ShouldAutorotateToInterfaceOrientation (UIInterfaceOrientation toInterfaceOrientation)
- {
-
- var manager = GameWindow.game.graphicsDeviceManager as GraphicsDeviceManager;
- Console.WriteLine(manager == null);
- if(manager == null)
- return true;
- DisplayOrientation supportedOrientations = manager.SupportedOrientations;
- switch(toInterfaceOrientation)
- {
- case UIInterfaceOrientation.LandscapeLeft :
- return (supportedOrientations & DisplayOrientation.LandscapeLeft) != 0;
- case UIInterfaceOrientation.LandscapeRight:
- return (supportedOrientations & DisplayOrientation.LandscapeRight) != 0;
- case UIInterfaceOrientation.Portrait:
- return (supportedOrientations & DisplayOrientation.Portrait) != 0;
- case UIInterfaceOrientation.PortraitUpsideDown :
- return (supportedOrientations & DisplayOrientation.PortraitUpsideDown) != 0;
- default :
- return false;
- }
- return true;
-
- }
-
- #region IGameWindow implementation
- public event EventHandler<EventArgs> Load;
-
- public event EventHandler<EventArgs> Unload;
-
- public event EventHandler<FrameEventArgs> UpdateFrame;
-
- public event EventHandler<FrameEventArgs> RenderFrame;
-
- public void Run ()
- {
- throw new NotImplementedException ();
- }
-
- public void Run (double updateRate)
- {
- throw new NotImplementedException ();
- }
-
- public void MakeCurrent ()
- {
- throw new NotImplementedException ();
- }
-
- public void SwapBuffers ()
- {
- throw new NotImplementedException ();
- }
- #endregion
-
- #region INativeWindow implementation
- public event EventHandler<EventArgs> Move;
-
- public event EventHandler<EventArgs> Resize;
-
- //public event EventHandler<CancelEventArgs> Closing;
-
- public event EventHandler<EventArgs> Closed;
-
- public event EventHandler<EventArgs> Disposed;
-
- public event EventHandler<EventArgs> TitleChanged;
-
- public event EventHandler<EventArgs> VisibleChanged;
-
- public event EventHandler<EventArgs> FocusedChanged;
-
- public event EventHandler<EventArgs> WindowBorderChanged;
-
- public event EventHandler<EventArgs> WindowStateChanged;
-
- public event EventHandler<KeyPressEventArgs> KeyPress;
-
- public void Close ()
- {
- throw new NotImplementedException ();
- }
-
- public void ProcessEvents ()
- {
- throw new NotImplementedException ();
- }
-
- public System.Drawing.Point PointToClient (System.Drawing.Point point)
- {
- throw new NotImplementedException ();
- }
-
- public System.Drawing.Point PointToScreen (System.Drawing.Point point)
- {
- throw new NotImplementedException ();
- }
-
- public bool Focused {
- get {
- throw new NotImplementedException ();
- }
- }
-
- public bool Visible {
- get {
- throw new NotImplementedException ();
- }
- set {
- throw new NotImplementedException ();
- }
- }
-
- public bool Exists {
- get {
- throw new NotImplementedException ();
- }
- }
-
- public IWindowInfo WindowInfo {
- get {
- throw new NotImplementedException ();
- }
- }
-
- public OpenTK.WindowState WindowState {
- get {
- throw new NotImplementedException ();
- }
- set {
- throw new NotImplementedException ();
- }
- }
-
- public OpenTK.WindowBorder WindowBorder {
- get {
- throw new NotImplementedException ();
- }
- set {
- throw new NotImplementedException ();
- }
- }
-
- public System.Drawing.Rectangle Bounds {
- get {
- throw new NotImplementedException ();
- }
- set {
- throw new NotImplementedException ();
- }
- }
-
- public System.Drawing.Point Location {
- get {
- throw new NotImplementedException ();
- }
- set {
- throw new NotImplementedException ();
- }
- }
-
- public System.Drawing.Size Size {
- get {
- throw new NotImplementedException ();
- }
- set {
- throw new NotImplementedException ();
- }
- }
-
- public int X {
- get {
- throw new NotImplementedException ();
- }
- set {
- throw new NotImplementedException ();
- }
- }
-
- public int Y {
- get {
- throw new NotImplementedException ();
- }
- set {
- throw new NotImplementedException ();
- }
- }
-
- public int Width {
- get {
- throw new NotImplementedException ();
- }
- set {
- throw new NotImplementedException ();
- }
- }
-
- public int Height {
- get {
- throw new NotImplementedException ();
- }
- set {
- throw new NotImplementedException ();
- }
- }
-
- public System.Drawing.Rectangle ClientRectangle {
- get {
- throw new NotImplementedException ();
- }
- set {
- throw new NotImplementedException ();
- }
- }
-
- public System.Drawing.Size ClientSize {
- get {
- throw new NotImplementedException ();
- }
- set {
- throw new NotImplementedException ();
- }
- }
- #endregion
- }
-}
+#region License
+/*
+Microsoft Public License (Ms-PL)
+MonoGame - Copyright © 2009-2012 The MonoGame Team
+
+All rights reserved.
+
+This license governs use of the accompanying software. If you use the software,
+you accept this license. If you do not accept the license, do not use the
+software.
+
+1. Definitions
+
+The terms "reproduce," "reproduction," "derivative works," and "distribution"
+have the same meaning here as under U.S. copyright law.
+
+A "contribution" is the original software, or any additions or changes to the
+software.
+
+A "contributor" is any person that distributes its contribution under this
+license.
+
+"Licensed patents" are a contributor's patent claims that read directly on its
+contribution.
+
+2. Grant of Rights
+
+(A) Copyright Grant- Subject to the terms of this license, including the
+license conditions and limitations in section 3, each contributor grants you a
+non-exclusive, worldwide, royalty-free copyright license to reproduce its
+contribution, prepare derivative works of its contribution, and distribute its
+contribution or any derivative works that you create.
+
+(B) Patent Grant- Subject to the terms of this license, including the license
+conditions and limitations in section 3, each contributor grants you a
+non-exclusive, worldwide, royalty-free license under its licensed patents to
+make, have made, use, sell, offer for sale, import, and/or otherwise dispose of
+its contribution in the software or derivative works of the contribution in the
+software.
+
+3. Conditions and Limitations
+
+(A) No Trademark License- This license does not grant you rights to use any
+contributors' name, logo, or trademarks.
+
+(B) If you bring a patent claim against any contributor over patents that you
+claim are infringed by the software, your patent license from such contributor
+to the software ends automatically.
+
+(C) If you distribute any portion of the software, you must retain all
+copyright, patent, trademark, and attribution notices that are present in the
+software.
+
+(D) If you distribute any portion of the software in source code form, you may
+do so only under this license by including a complete copy of this license with
+your distribution. If you distribute any portion of the software in compiled or
+object code form, you may only do so under a license that complies with this
+license.
+
+(E) The software is licensed "as-is." You bear the risk of using it. The
+contributors give no express warranties, guarantees or conditions. You may have
+additional consumer rights under your local laws which this license cannot
+change. To the extent permitted under your local laws, the contributors exclude
+the implied warranties of merchantability, fitness for a particular purpose and
+non-infringement.
+*/
+#endregion License
+
+using System;
+
+using MonoTouch.CoreAnimation;
+using MonoTouch.Foundation;
+using MonoTouch.ObjCRuntime;
+using MonoTouch.OpenGLES;
+using MonoTouch.UIKit;
+
+using OpenTK.Graphics;
+using OpenTK.Platform.iPhoneOS;
+
+using Microsoft.Xna.Framework.Graphics;
+using Microsoft.Xna.Framework.Input.Touch;
+
+using All = OpenTK.Graphics.ES20.All;
+
+namespace Microsoft.Xna.Framework {
+ partial class iOSGameView : UIView {
+ private readonly iOSGamePlatform _platform;
+ private int _renderbuffer;
+ private int _framebuffer;
+
+ #region Construction/Destruction
+ public iOSGameView (iOSGamePlatform platform)
+ : base(UIScreen.MainScreen.Bounds)
+ {
+ if (platform == null)
+ throw new ArgumentNullException ("platform");
+ _platform = platform;
+ Initialize ();
+ }
+
+ private void Initialize ()
+ {
+ MultipleTouchEnabled = true;
+ Opaque = true;
+ }
+
+ protected override void Dispose (bool disposing)
+ {
+ if (disposing) {
+ if (_graphicsContext != null)
+ DestroyContext();
+ }
+
+ base.Dispose (disposing);
+ _isDisposed = true;
+ }
+
+ #endregion Construction/Destruction
+
+ #region Properties
+
+ private bool _isDisposed;
+
+ public bool IsDisposed {
+ get { return _isDisposed; }
+ }
+
+ #endregion Properties
+
+ [Export ("layerClass")]
+ public static Class GetLayerClass ()
+ {
+ return new Class (typeof (CAEAGLLayer));
+ }
+
+ public override bool CanBecomeFirstResponder {
+ get { return true; }
+ }
+
+ private new CAEAGLLayer Layer {
+ get { return base.Layer as CAEAGLLayer; }
+ }
+
+ // FIXME: Someday, hopefully it will be possible to move
+ // GraphicsContext into an iOS-specific GraphicsDevice.
+ // Some level of cooperation with the UIView/Layer will
+ // probably always be necessary, unfortunately.
+ private GraphicsContext _graphicsContext;
+ private IOpenGLApi _glapi;
+ private void CreateContext ()
+ {
+ AssertNotDisposed ();
+
+ Layer.DrawableProperties = NSDictionary.FromObjectsAndKeys (
+ new NSObject [] {
+ NSNumber.FromBoolean (true),
+ EAGLColorFormat.RGBA8
+ },
+ new NSObject [] {
+ EAGLDrawableProperty.RetainedBacking,
+ EAGLDrawableProperty.ColorFormat
+ });
+
+ Layer.ContentsScale = Window.Screen.Scale;
+
+ //var strVersion = OpenTK.Graphics.ES11.GL.GetString (OpenTK.Graphics.ES11.All.Version);
+ //strVersion = OpenTK.Graphics.ES20.GL.GetString (OpenTK.Graphics.ES20.All.Version);
+ //var version = Version.Parse (strVersion);
+
+ try {
+ _graphicsContext = new GraphicsContext (null, null, 2, 0, GraphicsContextFlags.Embedded);
+ _glapi = new Gles20Api ();
+ } catch {
+ _graphicsContext = new GraphicsContext (null, null, 1, 1, GraphicsContextFlags.Embedded);
+ _glapi = new Gles11Api ();
+ }
+
+ _graphicsContext.MakeCurrent (null);
+ _graphicsContext.LoadAll ();
+ }
+
+ private void DestroyContext ()
+ {
+ AssertNotDisposed ();
+ AssertValidContext ();
+
+ _graphicsContext.Dispose ();
+ _graphicsContext = null;
+ _glapi = null;
+ }
+
+ private void CreateFramebuffer ()
+ {
+ AssertNotDisposed ();
+ AssertValidContext ();
+
+ _graphicsContext.MakeCurrent (null);
+
+ int previousRenderbuffer = 0;
+ _glapi.GetInteger (All.RenderbufferBinding, ref previousRenderbuffer);
+
+ _glapi.GenRenderbuffers (1, ref _renderbuffer);
+ _glapi.BindRenderbuffer (All.Renderbuffer, _renderbuffer);
+
+ var ctx = ((IGraphicsContextInternal) _graphicsContext).Implementation as iPhoneOSGraphicsContext;
+
+ // TODO: EAGLContext.RenderBufferStorage returns false
+ // on all but the first call. Nevertheless, it
+ // works. Still, it would be nice to know why it
+ // claims to have failed.
+ ctx.EAGLContext.RenderBufferStorage ((uint) All.Renderbuffer, Layer);
+
+ _glapi.GenFramebuffers (1, ref _framebuffer);
+ _glapi.BindFramebuffer (All.Framebuffer, _framebuffer);
+ _glapi.FramebufferRenderbuffer (
+ All.Framebuffer, All.ColorAttachment0, All.Renderbuffer, _renderbuffer);
+
+ var status = _glapi.CheckFramebufferStatus (All.Framebuffer);
+ if (status != All.FramebufferComplete)
+ throw new InvalidOperationException (
+ "Framebuffer was not created correctly: " + status);
+
+ // HACK: GraphicsDevice itself should be calling
+ // glViewport, so we shouldn't need to do it
+ // here and then force the state into
+ // GraphicsDevice. However, that change is a
+ // ways off, yet.
+ int unscaledViewportWidth = (int) Math.Round (Layer.Bounds.Size.Width);
+ int unscaledViewportHeight = (int) Math.Round (Layer.Bounds.Size.Height);
+
+ _glapi.Viewport (0, 0, unscaledViewportWidth, unscaledViewportHeight);
+ _glapi.Scissor (0, 0, unscaledViewportWidth, unscaledViewportHeight);
+
+ var gds = (IGraphicsDeviceService) _platform.Game.Services.GetService (
+ typeof (IGraphicsDeviceService));
+
+ if (gds != null) {
+ gds.GraphicsDevice.Viewport = new Viewport (
+ 0, 0,
+ (int) (Layer.Bounds.Width * Layer.ContentsScale),
+ (int) (Layer.Bounds.Height * Layer.ContentsScale));
+
+ // FIXME: The GraphicsDevice should be in charge of the
+ // framebuffer. Pushing the value into it from
+ // here is messy.
+ gds.GraphicsDevice.glFramebuffer = _framebuffer;
+ }
+ }
+
+ private void DestroyFramebuffer ()
+ {
+ AssertNotDisposed ();
+ AssertValidContext ();
+
+ _graphicsContext.MakeCurrent (null);
+
+ var ctx = ((IGraphicsContextInternal)_graphicsContext).Implementation as iPhoneOSGraphicsContext;
+ // FIXME: MonoTouch needs to allow null arguments to
+ // RenderBufferStorage, but it doesn't right now.
+ // So we call it manually.
+ //ctx.EAGLContext.RenderBufferStorage((uint)All.Renderbuffer, null);
+ var selector = new Selector("renderbufferStorage:fromDrawable:");
+ Messaging.bool_objc_msgSend_UInt32_IntPtr(
+ ctx.EAGLContext.Handle, selector.Handle, (uint)All.Renderbuffer, IntPtr.Zero);
+
+ _glapi.DeleteFramebuffers (1, ref _framebuffer);
+ _framebuffer = 0;
+
+ _glapi.DeleteRenderbuffers (1, ref _renderbuffer);
+ _renderbuffer = 0;
+ }
+
+ // FIXME: This logic belongs in GraphicsDevice.Present, not
+ // here. If it can someday be moved there, then the
+ // normal call to Present in Game.Tick should cover
+ // this. For now, iOSGamePlatform will call Present
+ // in the Draw/Update loop handler.
+ [Obsolete("Remove iOSGameView.Present once GraphicsDevice.Present fully expresses this")]
+ public void Present ()
+ {
+ AssertNotDisposed ();
+ AssertValidContext ();
+
+ _graphicsContext.MakeCurrent (null);
+
+ var ctx = ((IGraphicsContextInternal) _graphicsContext).Implementation as iPhoneOSGraphicsContext;
+ ctx.EAGLContext.PresentRenderBuffer ((uint) All.Renderbuffer);
+ }
+
+ // FIXME: This functionality belongs in GraphicsDevice.
+ [Obsolete("Move the functionality of iOSGameView.MakeCurrent into GraphicsDevice")]
+ public void MakeCurrent ()
+ {
+ AssertNotDisposed ();
+ AssertValidContext ();
+
+ _graphicsContext.MakeCurrent (null);
+ }
+
+ public override void LayoutSubviews ()
+ {
+ base.LayoutSubviews ();
+
+ if (_framebuffer != 0 || _renderbuffer != 0)
+ DestroyFramebuffer ();
+ if (_graphicsContext == null)
+ CreateContext();
+ CreateFramebuffer ();
+ }
+
+ #region UIWindow Notifications
+
+ public override void WillMoveToWindow (UIWindow window)
+ {
+ base.WillMoveToWindow (window);
+
+ if (Window != null)
+ TouchPanel.EnabledGesturesChanged -= TouchPanel_EnabledGesturesChanged;
+
+ if (_framebuffer != 0 || _renderbuffer != 0)
+ DestroyFramebuffer();
+ }
+
+ [Export ("didMoveToWindow")]
+ public virtual void DidMoveToWindow ()
+ {
+ if (Window != null) {
+ TouchPanel.EnabledGesturesChanged += TouchPanel_EnabledGesturesChanged;
+
+ if (_graphicsContext == null)
+ CreateContext ();
+ if (_framebuffer == 0 || _renderbuffer == 0)
+ CreateFramebuffer ();
+ }
+ }
+
+ #endregion UIWindow Notifications
+
+ private void AssertNotDisposed ()
+ {
+ if (_isDisposed)
+ throw new ObjectDisposedException (GetType ().Name);
+ }
+
+ private void AssertValidContext ()
+ {
+ if (_graphicsContext == null)
+ throw new InvalidOperationException (
+ "GraphicsContext must be created for this operation to succeed.");
+ }
+ }
+}
View
133 MonoGame.Framework/iOS/iOSGameViewController.cs
@@ -1,7 +1,7 @@
#region License
/*
Microsoft Public License (Ms-PL)
-MonoGame - Copyright © 2009-2011 The MonoGame Team
+MonoGame - Copyright © 2009-2012 The MonoGame Team
All rights reserved.
@@ -65,49 +65,96 @@ 1. Definitions
non-infringement.
*/
#endregion
-
using System;
using MonoTouch.UIKit;
-
-namespace Microsoft.Xna.Framework
-{
- class iOSGameViewController : UIViewController
- {
- iOSGamePlatform _platform;
- public iOSGameViewController(iOSGamePlatform platform)
- {
- if (platform == null)
- throw new ArgumentNullException("platform");
- _platform = platform;
- }
-
- public override void LoadView()
- {
- base.View = new GameWindow(_platform);
- }
-
- // HACK: Just adding a 'new' property here because it is convenient at
- // the moment. Eventually, GameWindow will be a common abstract
- // base class, and each platform will implement it in its own way.
- // For iOS, it should probably be the object that owns this view
- // controller, rather than inheriting from iPhoneOSGameView. But,
- // that change is a little ways off.
- public new GameWindow View
- {
- get { return (GameWindow)base.View; }
- }
-
- public override bool ShouldAutorotateToInterfaceOrientation(UIInterfaceOrientation toInterfaceOrientation)
- {
- var manager = (GraphicsDeviceManager)_platform.Game.Services.GetService(typeof(IGraphicsDeviceManager));
- if (manager == null)
- return toInterfaceOrientation == UIInterfaceOrientation.Portrait;
-
- var supportedOrientations = OrientationConverter.Normalize(manager.SupportedOrientations);
- var toOrientation = OrientationConverter.ToDisplayOrientation(toInterfaceOrientation);
-
- return (toOrientation & supportedOrientations) == toOrientation;
- }
- }
+using MonoTouch.Foundation;
+
+namespace Microsoft.Xna.Framework {
+ class iOSGameViewController : UIViewController {
+ iOSGamePlatform _platform;