Browse Source

Merge pull request #6 from kungfubanana/implicit_ordering

Adds TestImplicitOrdering test project
Kenneth Pouncey 13 years ago
parent
commit
c6abd4d933

BIN
Tests/MacOS/TestImplicitOrdering/Content/fntStandard.xnb


+ 172 - 0
Tests/MacOS/TestImplicitOrdering/ImplicitOrderingGame.cs

@@ -0,0 +1,172 @@
+using System;
+using System.Collections.Generic;
+
+using Microsoft.Xna.Framework;
+using Microsoft.Xna.Framework.Graphics;
+
+namespace TestImplicitOrdering
+{
+    public class ImplicitOrderingGame : Game
+    {
+        private SpriteBatch _spriteBatch;
+        private SpriteFont _font;
+
+        public ImplicitOrderingGame()
+        {
+            Content.RootDirectory = "Content";
+            new GraphicsDeviceManager(this);
+        }
+
+        private const int NumberOfBatches = 3;
+        private const int ItemsPerBatch = 3;
+        private int _batchNumber = 0;
+
+        private List<TestUpdateable> _updateables = new List<TestUpdateable>();
+        private List<TestUpdateable> _updateablesInUpdateOrder = new List<TestUpdateable>();
+        private bool _updateablesOrderedCorrectly;
+
+        private List<TestDrawable> _drawables = new List<TestDrawable>();
+        private List<TestDrawable> _drawablesInDrawOrder = new List<TestDrawable>();
+        private bool _drawablesOrderedCorrectly;
+
+
+        protected override void LoadContent()
+        {
+            base.LoadContent();
+
+            _spriteBatch = new SpriteBatch(GraphicsDevice);
+            _font = Content.Load<SpriteFont>("fntStandard");
+        }
+
+        protected override void UnloadContent()
+        {
+            base.UnloadContent();
+            _font = null;
+        }
+
+        protected override void Update(GameTime gameTime)
+        {
+            if (_batchNumber < NumberOfBatches &&
+                gameTime.TotalGameTime >= TimeSpan.FromSeconds(_batchNumber))
+            {
+                for (int i = 0; i < ItemsPerBatch; ++i)
+                {
+                    var updateable = new TestUpdateable(this);
+                    _updateables.Add(updateable);
+                    Components.Add(updateable);
+
+                    var drawable = new TestDrawable(this);
+                    _drawables.Add(drawable);
+                    Components.Add(drawable);
+                }
+
+                _batchNumber++;
+            }
+
+
+            base.Update(gameTime);
+            _updateablesOrderedCorrectly = ListsEqual(_updateables, _updateablesInUpdateOrder);
+            _updateablesInUpdateOrder.Clear();
+        }
+
+        protected override void Draw(GameTime gameTime)
+        {
+            GraphicsDevice.Clear(Color.CornflowerBlue);
+
+            base.Draw(gameTime);
+            _drawablesOrderedCorrectly = ListsEqual(_drawables, _drawablesInDrawOrder);
+            _drawablesInDrawOrder.Clear();
+
+            _spriteBatch.Begin();
+            DrawStatusString(
+                string.Format("{0} updateables", _updateables.Count),
+                1, _updateablesOrderedCorrectly);
+            DrawStatusString(
+                string.Format("{0} drawables", _drawables.Count),
+                0, _drawablesOrderedCorrectly);
+            _spriteBatch.End();
+        }
+
+        private void DrawStatusString(string item, int linesFromBottom, bool isCorrect)
+        {
+            var position = new Vector2(
+                10, GraphicsDevice.Viewport.Height - ((1 + linesFromBottom) * _font.LineSpacing));
+            if (isCorrect)
+                _spriteBatch.DrawString(_font, item + " correctly ordered!", position, Color.Lime);
+            else
+                _spriteBatch.DrawString(_font, item + " incorrectly ordered.", position, Color.Red);
+        }
+
+        private bool ListsEqual<T>(IList<T> a, IList<T> b)
+        {
+            if (a.Count != b.Count)
+                return false;
+
+            var equalityComparer = EqualityComparer<T>.Default;
+            for (int i = 0; i < a.Count; ++i)
+                if (!equalityComparer.Equals(a[i], b[i]))
+                    return false;
+            return true;
+        }
+
+        private class TestUpdateable : GameComponent
+        {
+            public TestUpdateable(Game game) : base(game) { }
+
+            public override void Update(GameTime gameTime)
+            {
+                base.Update(gameTime);
+
+                var game = (ImplicitOrderingGame)Game;
+                game._updateablesInUpdateOrder.Add(this);
+            }
+        }
+
+        private class TestDrawable : DrawableGameComponent
+        {
+            private static int InstanceCount = 0;
+            private static readonly Color[] Colors = new Color[]
+            {
+                Color.White, Color.Red, Color.Orange, Color.Yellow, Color.Green,
+                Color.Blue, Color.Indigo, Color.Violet, Color.Black
+            };
+
+            private int _number;
+            private Color _color;
+            public TestDrawable(Game game) : base(game)
+            {
+                _number = ++InstanceCount;
+                _color = Colors[_number % Colors.Length];
+            }
+
+            private SpriteBatch _spriteBatch;
+            protected override void LoadContent()
+            {
+                base.LoadContent();
+                _spriteBatch = new SpriteBatch(Game.GraphicsDevice);
+            }
+
+            protected override void UnloadContent()
+            {
+                base.UnloadContent();
+
+                _spriteBatch.Dispose();
+                _spriteBatch = null;
+            }
+
+            public override void Draw(GameTime gameTime)
+            {
+                var game = (ImplicitOrderingGame)Game;
+
+                game._drawablesInDrawOrder.Add(this);
+
+                float halfEx = game._font.MeasureString("x").X / 2;
+                var position = new Vector2(_number * halfEx, 0);
+
+                _spriteBatch.Begin();
+                _spriteBatch.DrawString(game._font, _number.ToString(), position, _color);
+                _spriteBatch.End();
+            }
+        }
+    }
+}

+ 16 - 0
Tests/MacOS/TestImplicitOrdering/Info.plist

@@ -0,0 +1,16 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+<dict>
+	<key>CFBundleIdentifier</key>
+	<string>com.yourcompany.TestImplicitOrdering</string>
+	<key>CFBundleName</key>
+	<string>TestImplicitOrdering</string>
+	<key>CFBundleVersion</key>
+	<string>1</string>
+	<key>LSMinimumSystemVersion</key>
+	<string>10.6</string>
+	<key>NSPrincipalClass</key>
+	<string>NSApplication</string>
+</dict>
+</plist>

+ 47 - 0
Tests/MacOS/TestImplicitOrdering/Main.cs

@@ -0,0 +1,47 @@
+using System;
+using System.Drawing;
+
+using MonoMac.Foundation;
+using MonoMac.AppKit;
+using MonoMac.ObjCRuntime;
+
+namespace TestImplicitOrdering
+{
+    class MainClass
+    {
+        static void Main(string[] args)
+        {
+            NSApplication.Init();
+            using (var pool = new NSAutoreleasePool())
+            {
+                NSApplication.SharedApplication.Delegate = new AppDelegate();
+                NSApplication.Main(args);
+            }
+        }
+    }
+
+    class AppDelegate : NSApplicationDelegate
+    {
+        private ImplicitOrderingGame _game;
+        public override void DidFinishLaunching(NSNotification notification)
+        {
+            _game = new ImplicitOrderingGame();
+            _game.Run();
+        }
+
+        public override void WillTerminate(NSNotification notification)
+        {
+            if (_game != null)
+            {
+                _game.Dispose();
+                _game = null;
+            }
+        }
+
+        public override bool ApplicationShouldTerminateAfterLastWindowClosed(NSApplication sender)
+        {
+            return true;
+        }
+    }
+}
+

+ 69 - 0
Tests/MacOS/TestImplicitOrdering/TestImplicitOrdering.csproj

@@ -0,0 +1,69 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">x86</Platform>
+    <ProductVersion>10.0.0</ProductVersion>
+    <SchemaVersion>2.0</SchemaVersion>
+    <ProjectGuid>{573AC418-8A76-4C5B-A7FE-5AC0A4C32BA1}</ProjectGuid>
+    <ProjectTypeGuids>{948B3504-5B70-4649-8FE4-BDE1FB46EC69};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+    <OutputType>Exe</OutputType>
+    <RootNamespace>TestImplicitOrdering</RootNamespace>
+    <AssemblyName>TestImplicitOrdering</AssemblyName>
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
+    <DebugSymbols>true</DebugSymbols>
+    <DebugType>full</DebugType>
+    <Optimize>false</Optimize>
+    <OutputPath>bin\Debug</OutputPath>
+    <DefineConstants>DEBUG;</DefineConstants>
+    <ErrorReport>prompt</ErrorReport>
+    <WarningLevel>4</WarningLevel>
+    <PlatformTarget>x86</PlatformTarget>
+    <ConsolePause>false</ConsolePause>
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
+    <DebugType>none</DebugType>
+    <Optimize>false</Optimize>
+    <OutputPath>bin\Release</OutputPath>
+    <ErrorReport>prompt</ErrorReport>
+    <WarningLevel>4</WarningLevel>
+    <PlatformTarget>x86</PlatformTarget>
+    <ConsolePause>false</ConsolePause>
+  </PropertyGroup>
+  <ItemGroup>
+    <Reference Include="System" />
+    <Reference Include="System.Xml" />
+    <Reference Include="System.Core" />
+    <Reference Include="System.Xml.Linq" />
+    <Reference Include="System.Drawing" />
+    <Reference Include="MonoMac" />
+  </ItemGroup>
+  <ItemGroup>
+    <Compile Include="Main.cs" />
+    <Compile Include="ImplicitOrderingGame.cs" />
+  </ItemGroup>
+  <ItemGroup>
+    <None Include="Info.plist" />
+  </ItemGroup>
+  <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
+  <Import Project="$(MSBuildExtensionsPath)\Mono\MonoMac\v0.0\Mono.MonoMac.targets" />
+  <ItemGroup>
+    <ProjectReference Include="..\..\..\..\MonoGame\MonoGame.Framework\MonoGame.Framework.MacOS.csproj">
+      <Project>{36C538E6-C32A-4A8D-A39C-566173D7118E}</Project>
+      <Name>MonoGame.Framework.MacOS</Name>
+    </ProjectReference>
+    <ProjectReference Include="..\..\..\..\MonoGame\ThirdParty\Lidgren.Network\Lidgren.Network.MacOS.csproj">
+      <Project>{AE483C29-042E-4226-BA52-D247CE7676DA}</Project>
+      <Name>Lidgren.Network.MacOS</Name>
+    </ProjectReference>
+  </ItemGroup>
+  <ItemGroup>
+    <Folder Include="Content\" />
+  </ItemGroup>
+  <ItemGroup>
+    <Content Include="Content\fntStandard.xnb">
+      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
+    </Content>
+  </ItemGroup>
+</Project>

+ 8 - 0
Tests/MonoGame.Tests.MacOS.sln

@@ -33,6 +33,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SoundTest_MacOS", "MacOS\So
 EndProject
 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SoundTest2_MacOs", "MacOS\SoundTest2\SoundTest2_MacOs\SoundTest2_MacOs.csproj", "{79A32C2C-0F38-4ADE-88D1-F8502C520570}"
 EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TestImplicitOrdering", "MacOS\TestImplicitOrdering\TestImplicitOrdering.csproj", "{573AC418-8A76-4C5B-A7FE-5AC0A4C32BA1}"
+EndProject
 Global
 	GlobalSection(SolutionConfigurationPlatforms) = preSolution
 		Debug|x86 = Debug|x86
@@ -64,6 +66,12 @@ Global
 		{51147863-7B4E-4467-A5FA-986259EB686F}.Distribution|Any CPU.Build.0 = Debug|x86
 		{51147863-7B4E-4467-A5FA-986259EB686F}.Release|x86.ActiveCfg = Release|x86
 		{51147863-7B4E-4467-A5FA-986259EB686F}.Release|x86.Build.0 = Release|x86
+		{573AC418-8A76-4C5B-A7FE-5AC0A4C32BA1}.Debug|x86.ActiveCfg = Debug|x86
+		{573AC418-8A76-4C5B-A7FE-5AC0A4C32BA1}.Debug|x86.Build.0 = Debug|x86
+		{573AC418-8A76-4C5B-A7FE-5AC0A4C32BA1}.Distribution|Any CPU.ActiveCfg = Debug|x86
+		{573AC418-8A76-4C5B-A7FE-5AC0A4C32BA1}.Distribution|Any CPU.Build.0 = Debug|x86
+		{573AC418-8A76-4C5B-A7FE-5AC0A4C32BA1}.Release|x86.ActiveCfg = Release|x86
+		{573AC418-8A76-4C5B-A7FE-5AC0A4C32BA1}.Release|x86.Build.0 = Release|x86
 		{79A32C2C-0F38-4ADE-88D1-F8502C520570}.Debug|x86.ActiveCfg = Debug|x86
 		{79A32C2C-0F38-4ADE-88D1-F8502C520570}.Debug|x86.Build.0 = Debug|x86
 		{79A32C2C-0F38-4ADE-88D1-F8502C520570}.Distribution|Any CPU.ActiveCfg = Debug|x86