PageRenderTime 103ms CodeModel.GetById 40ms app.highlight 9ms RepoModel.GetById 52ms app.codeStats 0ms

/Scenes/Tests/PerformanceTests.cs

#
C# | 179 lines | 150 code | 13 blank | 16 comment | 12 complexity | deb26db32f997ed6ccc748a36188b410 MD5 | raw file
  1using Delta.ContentSystem;
  2using Delta.Engine;
  3using Delta.InputSystem;
  4using Delta.Rendering.Basics.Materials;
  5using Delta.Rendering.Enums;
  6using Delta.Scenes.UserInterfaces;
  7using Delta.Scenes.UserInterfaces.Controls;
  8using Delta.Utilities.Datatypes;
  9using NUnit.Framework;
 10
 11namespace Delta.Scenes.Tests
 12{
 13	/// <summary>
 14	/// Performance tests
 15	/// </summary>
 16	internal class PerformanceTests
 17	{
 18		#region TestBackgroundSpeed (LongRunning)
 19		/// <summary>
 20		/// Test background speed, press 1, 2, 3, or 0 to change the background!
 21		/// </summary>
 22		[Test, Category("Visual")]
 23		public static void TestBackgroundSpeed()
 24		{
 25			Screen scene = new Screen();
 26			scene.Open();
 27
 28			Application.Start(delegate
 29			{
 30				if (Input.Keyboard.GetState(InputButton.D1) == InputState.Pressed)
 31				{
 32					scene.Background = new Material2DColored("SimpleMainMenuBackground")
 33					{
 34						DrawLayer = RenderLayer.Background,
 35					};
 36				}
 37				else if (Input.Keyboard.GetState(InputButton.D2) == InputState.Pressed)
 38				{
 39					scene.Background = new Material2DColored("DeltaEngineLogo")
 40					{
 41						DrawLayer = RenderLayer.Background,
 42					};
 43				}
 44				else if (Input.Keyboard.GetState(InputButton.D3) == InputState.Pressed)
 45				{
 46					scene.Background = new Material2DColored(Content.EmptyName)
 47					{
 48						DrawLayer = RenderLayer.Background,
 49					};
 50				}
 51				else if (Input.Keyboard.GetState(InputButton.D0) == InputState.Pressed)
 52				{
 53					scene.Background = null;
 54				}
 55			});
 56		}
 57		#endregion
 58
 59		#region ScreenPerformance (LongRunning)
 60		/// <summary>
 61		/// Screen performance
 62		/// </summary>
 63		[Test, Category("Visual")]
 64		public static void ScreenPerformance()
 65		{
 66			Screen controlsScreen = new Screen("<ControlsScreen>")
 67			{
 68				Background = new Material2DColored("SpaceBackground")
 69				{
 70					DrawLayer = RenderLayer.Background,
 71				},
 72			};
 73
 74			const float xPosOffset = 0.075f;
 75			const float yPosOffset = 0.075f;
 76
 77			for (int index = 0; index < 1; index++)
 78			{
 79				float xPos = 0.15f + index * xPosOffset;
 80				float yPos = 0.275f;
 81
 82				#region Adding an Image control
 83				Image image = new Image
 84				{
 85					Name = "Image control " + index,
 86					LocalArea = Rectangle.FromCenter(xPos, yPos, 0.2f, 0.075f),
 87					CustomDesign = new ControlDesign
 88					{
 89						Background = BaseTheme.GetUIMaterial("DeltaEnginelogo")
 90					},
 91					//Alignment = Alignment.TopLeft,
 92				};
 93				controlsScreen.Add(image);
 94				yPos += yPosOffset;
 95				#endregion
 96
 97				#region Adding a Label control
 98				Label label = new Label
 99				{
100					Name = "Label control " + index,
101					LocalArea = Rectangle.FromCenter(xPos, yPos, 0.2f, 0.05f),
102					Text = "Label text",
103					//Alignment = Alignment.Top,
104				};
105				controlsScreen.Add(label);
106				yPos += yPosOffset;
107				#endregion
108
109				#region Adding a Button control
110				Button button = new Button
111				{
112					Name = "Button control " + index,
113					LocalArea = Rectangle.FromCenter(xPos, yPos, 0.2f, 0.05f),
114					Text = "Button text",
115					//Alignment = Alignment.TopRight,
116				};
117				controlsScreen.Add(button);
118				yPos += yPosOffset;
119				#endregion
120
121				#region Adding a Slider control
122				Slider slider = new Slider
123				{
124					Name = "Slider control " + index,
125					LocalArea = Rectangle.FromCenter(xPos, yPos, 0.2f, 0.05f),
126					Text = "Slider text",
127					MinValue = 1,
128					MaxValue = 3,
129					Value = 1.5f,
130					//Alignment = Alignment.Left,
131				};
132				controlsScreen.Add(slider);
133				yPos += yPosOffset;
134				#endregion
135
136				#region Adding a Checkbox control
137				Checkbox checkbox = new Checkbox
138				{
139					Name = "Checkbox control " + index,
140					LocalArea = Rectangle.FromCenter(xPos, yPos, 0.2f, 0.05f),
141					Text = "Checkbox text",
142					IsChecked = true,
143					//Alignment = Alignment.Center,
144				};
145				controlsScreen.Add(checkbox);
146				yPos += yPosOffset;
147				#endregion
148
149				#region Adding a RadioButton control
150				RadioButton radioButton = new RadioButton
151				{
152					Name = "RadioButton control " + index,
153					LocalArea = Rectangle.FromCenter(xPos, yPos, 0.2f, 0.05f),
154					Text = "RadioButton text",
155					IsChecked = true,
156					//Alignment = Alignment.Right,
157				};
158				controlsScreen.Add(radioButton);
159				yPos += yPosOffset;
160				#endregion
161
162				#region Adding a TextBox control
163				TextBox textBox = new TextBox
164				{
165					Name = "TextBox control " + index,
166					LocalArea = Rectangle.FromCenter(xPos, yPos, 0.2f, 0.05f),
167					Text = "TextBox text",
168					//Alignment = Alignment.Bottom,
169				};
170				controlsScreen.Add(textBox);
171				yPos += yPosOffset;
172				#endregion
173			} // for
174
175			Application.Start(Scene.Open(controlsScreen));
176		}
177		#endregion
178	}
179}